在矩阵上应用Reduce

时间:2018-10-10 19:58:02

标签: r reduce

我试图将Reduce函数与|OR)和accumulate = TRUE应用于矩阵的列上。

示例输入:

m <- matrix(c(1,0,0,0,1,0,0,0,1), nrow = 3)

      [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1

结果应该是

m2 <- matrix(c(1,0,0,1,1,0,1,1,1), nrow = 3)

      [,1] [,2] [,3]
[1,]    1    1    1
[2,]    0    1    1
[3,]    0    0    1

0 个答案:

没有答案