R: How to sum pairs in a Matrix by row?

前端 未结 5 725
臣服心动
臣服心动 2021-01-23 02:54

Probably this would be easy. I have a Matrix:

testM <- matrix(1:40, ncol = 4, byrow = FALSE)
testM
      [,1] [,2] [,3] [,4]
 [1,]    1   11   21   31
 [2,]           


        
5条回答
  •  孤街浪徒
    2021-01-23 03:22

    How about:

    matrix(c(testM[, 1] + testM[, 2], testM[, 2] + testM[, 4]), nrow = 10)
    

提交回复
热议问题