Exactly as it sounds. I want to take a matrix and for each row, sum every n columns. I do not want to use apply or any loop wrapper. It needs to be as fast as possible. For example, see the below
set.seed(1)
M = matrix(rpois(16,4),4,4)
n = 2
M
[,1] [,2] [,3] [,4]
[1,] 3 2 5 5
[2,] 3 7 1 3
[3,] 4 7 2 5
[4,] 7 5 2 4
output
[,1] [,2]
[1,] 5 10
[2,] 10 4
[3,] 11 7
[4,] 12 6