I have a dataset like below:
BRAND MEDIUM W1 W2 W3 W4 W5
B1 tv 1 0 1 0 2
B2 tv 0 0 0 0 0
B1 radio 0 1 2 5 3
B1 tv 0 0 0 0 0
B2 radio 0 4 1 1 1
B1 newspapers 7 4 2 1 0
What I am trying to do is to group by BRAND and sum the value along each column to form a unique row made up of the summed values. Furthermore I'd also like to show which MEDIUM were in each subgroup.
The final output should be the following:
W1 W2 W3 W4 W5 tv radio newspaper
B1 8 9 5 6 5 1 1 1
B2 0 4 1 1 1 1 1 0
I'm having hard time to find a way to solve this, especially the second part to put which medium was in the group. Any suggestion or hints? Thanks