So I have the following matrix (let's call it output):
> output
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 1 1 0 0 1
[2,] 1 1 1 0 0 1
[3,] 1 1 1 0 0 1
[4,] 0 0 0 0 0 0
[5,] 1 0 1 1 0 0
[6,] 1 0 1 1 0 0
What I want to do is to create a new matrix (output2) by adding rows in groups of two. For example the first row of the new matrix would be:
output2[1,] <- output[1,] + output[2,]
The second row of the new matrix output2 would consist of the sum of the third and fourth row of the old output matrix:
output2[2,] <- output[3,] + output[4,]
And so forth. I was wondering what is the best way to code this, considering I will need to do the same to bigger matrices. I was considering creating dummy variables with the seq() function and maybe a for loop.
Is there a simpler way?
Edit:
dput(output)
structure(c(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0), .Dim = c(10L, 19L))