I have a dataframe with three vectors:
location size sales
A 1 100
A 1 300
A 2 200
A 3 300
B 1 300
B 1 500
C 1 800
C 1 900
B 3 500
B 3 600
I want to output a matrix with location on the X axis, size on the Y axis and mean sales of each (location, size) coordinate in the cells (sorted ascending on each axis).
A B C
1 200 400 850
2 200
3 300 550
...
I am new to R. I think I need to use the aggregate function. Thank you!