Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use R to find the total amount of units sold for each weekday (Entries in the “D

ID: 3804006 • Letter: U

Question

Use R to find the total amount of units sold for each weekday (Entries in the “Day” column {1, 2, 3, 4, 5, 6, 7} correspond to {Mon, Tue, Wed, Thu, Fri, Sat, Sun} respectively).


(a) Find the percentage of total units sold for each weekday (The R code is partially given and you need to fill the blanks first before running the code).

vec <- c()
for (i in 1:7){
df_day <- retail_store_1542[ , ] # fill the blank
vec <- c(vec, sum(df_day$ )) # fill the blank
}
table1 <- data.frame(weekday=vec, pecentage = vec/sum(vec))


(b) Plot a line plot (x axis represents “Weekday”, and y axis represents the amount of units sold per
week).

1 TransactionID ItemType VendorID Item ID CustomerID Week Day StorelD UnitsSold Couponorigin CouponValue (Cents) CouponID 5 43000 4187 15101 121 651 1 1542 1 51 110 626 18555 12 41280 3588 15101 246 651 1 1542 1 0 1 18556 4 18556 133 21000 1115 15101246 651 1 1542 1 0 0 1 20 46400 4668 15101 246 651 1 1542 0 0 1 18556 6 18556 20 46400 4676 15101 246 651 1 1542 1 0 0 1 7 18556 20 49000 4829 15101 246 651 1 1542 6 0 0 1 18558 4 79100 6758 15105973 651 1 1542 9 0 0 1 9 18558 4 79100 6774 15105973 651 1 1542 3 0 0 1 10 18560 8 70140 5460 15107227 651 1 1542 1 0 0 1 11 18560 11 72290 5879 15107 227 651 1 1542 1 0 0 1 12 18560 133 50711 5018 15107227 651 1 1542 1 0 0 1 13 18560 18 37000 2508 15107 227 651 1 1542 1 23 30 96 14 18560 20 49000 4847 15107227 651 1 15 42 2 0 0 1 15 18560 21 15800 579 15107227 651 1 1542 2 0 0 1 16 18561 9 41280 3524 15107797 6511 1 15 42 1 0 1 17 18561 22 41280 3555 15107 7907 651 1 1542 2 0 0 1 18 18562 133 21000 1075 15110924 6511 1 15 42 1 0 0 1 19 18562 15 19810 1002 15110924 651 1 1542 1 0 0 1 20 18563 22 41280 3737 1511 2292 651 1 1542 5 0 1 21 18564 5 16000 625 15113 651 1 1542 1 23 75 124 3126 22 18564 5 38000 2895 1511 3126 651 1 1542 1 23 92 130 23 18564 9 41280 3513 15113126 651 1 15 42 2 0 0 1 24 18564 9 41280 3524 151 13126 651 1 1542 1 0 0 1

Explanation / Answer

a)
vec <- c()
for (i in 1:7){
df_day <- retail_store_1542[$TR == i, "Day"]
vec <- c(vec, sum(df_day$ )) # fill the blank
}
table1 <- data.frame(weekday=vec, pecentage = vec/sum(vec))

b)
vec <- c()
for (i in 1:7){
df_day <- retail_store_1542[$TR == i, "Day"] # fill the blank
vec <- c(vec, sum(df_day$ )) # fill the blank
}
table1 <- data.frame(weekday=vec, pecentage = vec/sum(vec))
plot(vec,c(1,2,3,4,5,6,7),xlab="Weekday",ylab="Amount of units sold",pch=2)
title("Weekday vs units sold)