Detailed description |
Here is how to reproduce:
library(Matrix)
m <- matrix(c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE), ncol=2)
lgr <- as(m, "RsparseMatrix")
lgr
# 4 x 2 sparse Matrix of class "lgRMatrix"
#
# [1,] . |
# [2,] . |
# [3,] | .
# [4,] . |
This is correct (same as which(m)):
which(lgr)
# [1] 3 5 6 8
This is not correct:
which(lgr, arr.ind=TRUE)
# row col
# [1,] 1 2
# [2,] 2 2
# [3,] 3 1
# [4,] 4 2
The array-indices are correct but they are listed in the wrong order (they're listed row by row instead of column by column).
The correct answer is:
which(m, arr.ind=TRUE)
# row col
# [1,] 3 1
# [2,] 1 2
# [3,] 2 2
# [4,] 4 2
This is with Matrix 1.5-4.1 and R 4.3.0 on a 64-bit Intel machine running Ubuntu 23.04.
Best,
H. |
|