I have a matrix like this
P A B C
1 2 0 5
2 1 1 3
3 0 4 7
1 1 1 0
3 1 1 0
3 0 2 1
2 3 3 4
I want to merge/sort the rows by P and by each of the columns. So that each P value is for each column once and the value for each P in each column is summed up. The result should be:
P A B C
1 3 0 0
1 0 1 0
1 0 0 5
2 4 0 0
2 0 4 0
2 0 0 7
3 1 0 0
3 0 7 0
3 0 0 8
I tried already aggregate
but it only helps me to sum up every P value for all columns so that I have just one row for each P.