I've got this data frame which has duplicates (same ID
but different numbers):
ID X1 X2 X3 X4 X5
45 1 0 0 1 0
45 0 1 0 0 1
15 1 0 1 0 0
7 1 0 1 1 0
7 0 1 0 0 0
I want to sum the vectors that have the same ID so I've used rowsum
:
m <- rowsum(m, m$ID)
However it messes up with the order of the rows showing something like this:
ID X1 X2 X3 X4 X5
15 1 0 1 0 0
45 1 1 0 1 1
7 1 1 1 1 0
Instead of what I want:
ID X1 X2 X3 X4 X5
45 1 1 0 1 1
15 1 0 1 0 0
7 1 1 1 1 0
Anyone knows how to fix this?