little advice on the right application of dplyr in R is welcome.
We have following data:
City Amount Category
1 Los Angeles 100 Film
2 Los Angeles 200 Film
3 Los Angeles 400 Music
4 Seattle 300 Coffee
5 Boston 600 Books
...
Final result should look like:
Film Coffee Books ...
City
Los Angeles, CA Sum Sum Sum Sum
Seattle, WA Sum Sum Sum Sum
Boston, MA Sum Sum Sum Sum
I want the pivot table to summarize the total value of "Amount" for each Category in each city, so that cities are on the left in a column and all categories on top as a row.
Tried:
data %>%
group_by(Location, Category) %>%
summarise(Amount = sum(Amount))
Which looks more like
City Amount Category
1 Los Angeles 300 Film
3 Los Angeles 400 Music
4 Seattle 300 Coffee
5 Boston 600 Books
Computations are correct, but as described, we need City and Category as a matrix with the sum of each Amount inside the respective cell.
Thanks for your help!