R - return position of element in matrix?

前端 未结 2 1261
执笔经年
执笔经年 2020-12-08 08:14

Given a matrix:

      [,1] [,2]
[1,]    0  0.0
[2,]   -1  0.8

What is the quickest way in R to iterate over the matrix and return the posit

2条回答
  •  北海茫月
    2020-12-08 08:39

    m <- matrix(c(0, 1, 1, 0), nrow = 2)
    which(m != 0)
    

    or maybe

    which(m != 0, TRUE)
    

提交回复
热议问题