I am trying to summarize data based on month. For example, I have this data set:
x
Date App Vol
1 2010-01-30 A 100
2 2010-01-28 B 140
3 2010-01-30 C 160
4 2010-02-28 A 110
5 2010-02-28 B 120
6 2010-02-28 C 300
I would like to be able to summary App data by each month. According to the data frame above,
A should be 210, B = 260, C=460 etc.
I am using aggregate function ase below, but getting errors:
y<-aggregate(x$Vol, list(Month = format(as.POSIXct(x$Date), "%Y-%m")), sum)
any ideas?
Start with turning
Volinto numeric (it got messed up somehow):I can reproduce your eror by turning
Volinto a factor as seen here:Also you say:
If this is the case use:
Otherwise use ttmacer’s suggestion.