I would like to process the following matrix data by using which(), and return all the row names, for example:
m = matrix(seq(-1,1, 0.5), nrow = 3)
# [,1] [,2]
#[1,] -1.0 0.5
#[2,] -0.5 1.0
#[3,] 0.0 -1.0
which(m==0.5,arr.ind=TRUE)
# row col
# [1,] 1 2
How can I get the matrix like this? All row names can be shown in the table, and the missing value in col is NA.
# row col
# [1,] 1 2
# [2,] 2 NA
# [3,] 3 NA
# [4,] 4 NA