Page 1 of 1

Given the following sales matrix data, where each row represents the sales of the different stores and each column repre

Posted: Sun May 15, 2022 10:06 am
by answerhappygod
Given the following sales matrix data, where
each row represents the sales of the different stores
and each column represents the weekly sales of that store, write
the R code
for the questions below using the sales variable
and without any loops.
The solution should work for any number of stores and any number of
weeks.

data <- c(790, 895, 865, 230, 470, 715, 685, 890, 375, 645, 580,
795, 495, 830, 170, 460, 160, 200, 880, 760, 150, 635, 615, 360,
115, 680, 410, 505, 225, 320)

sales <- matrix(data, ncol = 6, byrow = TRUE)

a) What is the maximum number of sales for each
store?

b) Which week were those maximum sales for each
store?

c) If the target for maximum sales for each store
is 695,
by how much each store's maximum sales were off from the
target?

d) Using the paste function, and
using the results from a), b) and c),
produce the output as shown below.
Note that the solution should work for any number of stores and any
number of weeks.

[1]"Store 1 maximum sales of 895 in Week 2 and exceeds target 695
by 200"
[2]"Store 2 maximum sales of 890 in Week 2 and exceeds target 695
by 195"
[3]"Store 3 maximum sales of 830 in Week 2 and exceeds target 695
by 135"
[4]"Store 4 maximum sales of 880 in Week 1 and exceeds target 695
by 185"
[5]"Store 5 maximum sales of 680 in Week 2 and trails target 695 by
15"