I have a dataset which contains weekly sale of various products by outlet. Here is how the data looks like:
Store ID Week ID Item Code Sales in $
253422 191 41130 2.95
272568 188 41130 2.95
272568 188 41160 2.95
272568 189 41130 2.95
272568 189 41160 2.95
272568 190 41160 2.95
217460 188 41110 2.95
217460 188 41130 5.9
217460 188 41160 5.9
217460 189 41110 11.8
217460 189 41130 8.85
217460 189 41160 11.8
217460 191 41130 5.95
217460 191 41160 8.93
This is a very large dataset and I would like to generate a summary output which gives me the ITEM wise total sales and the number of stores in which the item is present. I tried the following, but that doesn't work because I get a store count which is repeated due to the repetition of weeks in the dataset:
dataset %>% group_by(Store ID) %>% summarize(count(Item Code))
Any help is highly appreciated. Thanks
You can do this with
aggregate
Here's a way to do it using
dplyr