So, I have the following matrix (let its output be called):
> 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 create a new matrix (output2) by adding rows to two groups. For example, the first row of the new matrix will be as follows:
output2[1,] <- output[1,] + output[2,]
The second row of the new output matrix file will consist of the sum of the third and fourth rows of the old output matrix:
output2[2,] <- output[3,] + output[4,]
And so on. I was wondering how best to encode this, given that I would need to do the same with large matrices. I considered creating dummy variables using the seq () function and possibly a for loop.
Is there an easier way?
Edit:
dput (exit)
(c (1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 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, 0, 0, 1, 0, 0 , 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 , 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0 , 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 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, 1 , 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0 , 0, 0, 0, 1, 0, 0, 0, 0, 0, 0), Dim = c (10L, 19L))