This question already has an answer here:
- Sum by two variables 2 answers
I have one dataframe:
Date area sales
1 201204 shanghai 23
2 201204 beijing 25
3 201204 beijing 16
4 201205 shanghai 55
5 201205 beijing 17
6 201205 shanghai 16
what I want to output is a table as follows:
Date shanghai beijing
201204 23 41
201205 71 17
How would I do this in R? Thanks!
Two options, one with base function
aggregate
, the other with plyr'sddply
. I made up my own data since yours isn't reproducible, but you should be able to get the point: