df
date storeid itemid sales biscuits jelly
1 2013-01-01 1 1 13 2 5
2 2013-01-01 1 2 11 3 2
3 2013-01-02 2 1 14 4 3
4 2013-01-02 1 1 13 6 1
..........................
1000 2015-12-05 1 1 10 1 12 and so on
I have this dataframe. I need something like this:
Year-month storeid itemid sum_sales count_biscuits mean_jelly
2013-01 1 1 12 13 20
2013-01 1 1 13 10 30
and so on.
So basically I wish to aggregate or groupby on 3 keys: year-month, store id and itemid. After that I want to calculate sum of sales, count of biscuits and mean of jelly.
df$Year-month <- format(as.Date(df$date), "%Y-%m")
group1<-df %>% group_by(storeid, itemid, Year-month ) %>% summarise(sum_sales = sum(sales))
How to add count of biscuits and mean of jelly. New to R so dont know how to do named aggregations here