Supermarket <-read_csv("SupermarketTransactions.csv", cols(Transaction = col_integer(), `Purchase Date` = col_character(), `Customer ID` = col_integer(), Gender = col_character(), `Marital Status` = col_character(), Homeowner = col_character(), Children = col_integer(), `Annual Income` = col_character(), City = col_character(), `State or Province` = col_character(), Country = col_character(), `Product Family` = col_character(), `Product Department` = col_character(), `Product Category` = col_character(), `Units Sold` = col_integer(), Revenue = col_double()), col_names = T) #read the csv file first
Filter the date:
Supermarket$`Purchase Date` <- as.Date(Supermarket$`Purchase Date`, "%m/%d/%Y") #convert the data type of date from string to date
Supermarket1 <-filter(Supermarket, Supermarket$`Purchase Date`>="2008-01-01" & `Purchase Date` <= "2008-02-29")#filter the date
The barplot:
barplot(table(Supermarket1$`Units Sold`), xlab= "Units Sold", main = "Barplot of Units Sold (January & February)")
The histogram:
hist(Supermarket1$Revenue,xlab = "Revenue", main = "Histogram of Revenue (January & February)")
Filter with the following conditions: Married, Female, Homeowners, and CA
df.mfhsC <-subset(Supermarket, `Marital Status` == "M" & Gender == "F" & Homeowner == "Y" & `State or Province` == "CA") #filter with the conditions and assign the data to df.mfhsC
The barplot:
barplot(table(df.mfhsC$`Units Sold`), xlab= "Units Sold", main = "Barplot of Units Sold (Married female homeowners in state of California)")
The histogram:
hist(df.mfhsC$Revenue,xlab = "Revenue", main = "Histogram of Revenue (Married female homeowners in state of California)")