Get row and column indices of matches using `which()`

For your first question you need to also pass arr.ind= TRUE to which:

> which(m == 1, arr.ind = TRUE)
     row col
[1,]   3   1
[2,]   2   2
[3,]   1   3
[4,]   4   3

Leave a Comment