Write a program that for a given customer_id shows the distribution of purchases made by that customer over different days of the week.
data <- read.csv("C:/Users/Dell/Documents/shoppingdata/dataSet2.csv",header = TRUE, stringsAsFactors = FALSE)
n <- readline(prompt="Enter Customer_id: ")
## Enter Customer_id:
head(data)
Compute weekdays for all the dates for the given customer_id
WeekDay <- format(as.Date(data[data["CUSTOMER_ID"] == n,"DATE"], "%m/%d/%Y"), "%A")
tempData <- cbind(data[data["CUSTOMER_ID"] == n,],WeekDay)
head(tempData)
Number of purchases over different days of a week
finalData <- aggregate(PRODUCT_ID ~ WeekDay,data = tempData,"length")
## Error in aggregate.data.frame(mf[1L], mf[-1L], FUN = FUN, ...): no rows to aggregate
colnames(finalData) <- c("WeekDay","Count of Purchases")
## Error in colnames(finalData) <- c("WeekDay", "Count of Purchases"): object 'finalData' not found
# paste0("Distribution of Purchases over different days of a week for the cust_id:",n)
finalData
## Error in eval(expr, envir, enclos): object 'finalData' not found