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).
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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.