I am troubleshooting the R's row sum function. I have the following vector called total:
1 3
1 45
.. ..
20 45
20 46
The vector has 20 different categories, and I would like to sum all the values for each category. My code is:
rowsum(total[,c(1:20)], group = c(1:20))
But I get the following error:
Error in rowsum.default(total[, c(1:2)], group = c(1:20)) incorrect length for 'group'
I am a bit confused because in the documentation, "group" is a vector/factor giving the grouping with one element per row of x.
Any help would be appreciated.
Thank you!