I would like to combine/sum two rows based on rownames to make one row in R. The best route might be to create a new row and sum the two rows together.
Example df:<
matrix multiply?
> A <- matrix(c(1,0,0,0,1,0,1,0,0,0,0,1), 3) > A [,1] [,2] [,3] [,4] [1,] 1 0 1 0 [2,] 0 1 0 0 [3,] 0 0 0 1 > A %*% X V2 V3 V4 V5 [1,] 7 11 5 8 [2,] 3 2 7 9 [3,] 3 2 8 9
Or using the Matrix package for sparse matrices:
Matrix
fac2sparse(factor(c(1,2,1,4))) %*% X