So I have taken a look at this question posted before which was used for summing every 2 values in each row in a matrix. Here is the link: sum specific columns among rows. I als
I would do something similar to the OP -- apply rowSums on subsets of the matrix:
rowSums
n = 3 ng = ncol(y)/n sapply( 1:ng, function(jg) rowSums(y[, (jg-1)*n + 1:n ])) # [,1] [,2] [,3] # [1,] 12 39 66 # [2,] 15 42 69 # [3,] 18 45 72