rm(list=ls())
# The following list contains the data for a chain of hardware stores
# From October 2021.
#
# The data for each store in the chain is stored in a separate list within
# the list of stores.
#
# The first two items in the list are the year and month for the data.
# The other items in the list are lists of information for each store in
# the chain. For simplicity, the data below only shows three stores. However,
# there could be many stores in the chain, each with similarly structured data.
#
# Each store is allowed to set their own prices and salePrices.
# Each store is also allowed to carry a somewhat different selection of
# products than the other stores.
#
# Answer the questions below by referring to this data. You should
# write the code so that it will continue to work even if the actual
# values in the data change.
= list(
stores
year=2021,
month=10,
list(
address="123 main street",
storeId="1000",
manager="joe",
products = data.frame(
product = c("hammer", "screwdriver", "hand saw", "wrench" ),
price= c(10.99, 8.00, 15.00, 5.00),
salePrice= c(8.99, NA, NA, 4.50),
amountSold= c(100, 200, 50, 75),
amountInInventory= c(20, 12, 0, 5)
)
),
list(
address="99 hickory place",
storeId="1111",
manager="sue",
products = data.frame (
product = c("wrench","screwdriver", "screws", "nails","pliers" ),
price= c(11.99, 8.00, 3.50, 2.99, 4.99),
salePrice= c(NA, 7.00, NA, 2.50, 4.50),
amountSold= c(80, 195, 200, 400, 80),
amountInInventory= c(20, 15, 40, 15, 0)
)
),
list(
address="450 broadway",
storeId="2345",
manager="carla",
products = data.frame (
product = c("wrench","saw","hammer","screws", "nails","drill" ),
price= c(11.99, 8.00, 11.00, 3.50, 2.99, 44.99),
salePrice= c(NA, 7.00, 10.00, 2.50, 2.50, NA),
amountSold= c(40, 100, 3, 100, 200, 10),
amountInInventory= c(30, 5, 40, 0, 0, 3)
)
)
# If there were more stores then the data for the other
# stores would appear as separate lists here.
)
# NOTE - the following command may help you to understand the data better
str(stores)
List of 5
$ year : num 2021
$ month: num 10
$ :List of 4
..$ address : chr "123 main street"
..$ storeId : chr "1000"
..$ manager : chr "joe"
..$ products:'data.frame': 4 obs. of 5 variables:
.. ..$ product : chr [1:4] "hammer" "screwdriver" "hand saw" "wrench"
.. ..$ price : num [1:4] 11 8 15 5
.. ..$ salePrice : num [1:4] 8.99 NA NA 4.5
.. ..$ amountSold : num [1:4] 100 200 50 75
.. ..$ amountInInventory: num [1:4] 20 12 0 5
$ :List of 4
..$ address : chr "99 hickory place"
..$ storeId : chr "1111"
..$ manager : chr "sue"
..$ products:'data.frame': 5 obs. of 5 variables:
.. ..$ product : chr [1:5] "wrench" "screwdriver" "screws" "nails" ...
.. ..$ price : num [1:5] 11.99 8 3.5 2.99 4.99
.. ..$ salePrice : num [1:5] NA 7 NA 2.5 4.5
.. ..$ amountSold : num [1:5] 80 195 200 400 80
.. ..$ amountInInventory: num [1:5] 20 15 40 15 0
$ :List of 4
..$ address : chr "450 broadway"
..$ storeId : chr "2345"
..$ manager : chr "carla"
..$ products:'data.frame': 6 obs. of 5 variables:
.. ..$ product : chr [1:6] "wrench" "saw" "hammer" "screws" ...
.. ..$ price : num [1:6] 11.99 8 11 3.5 2.99 ...
.. ..$ salePrice : num [1:6] NA 7 10 2.5 2.5 NA
.. ..$ amountSold : num [1:6] 40 100 3 100 200 10
.. ..$ amountInInventory: num [1:6] 30 5 40 0 0 3