months and 9 years ago
updated ten months ago
71,013 times total
39
5 Let's say I have a matrix, for instance:
nrow = 4 and m = matrix(rep(c(0, 0, 1), 4)
m
[,1] [,2] [,3]
[1,] 0 0 1 [2,] 0 1 0 [3,] 1 0 0 [4,] 0 0 1
I receive a list of standard indices if I run which:
where (m == 1)
[1] 3 6 9 12
I'm trying to get matrix indices, where each index has the row and column numbers:
[,1] [,2]
[1,] 3 1\s[2,] 2 2 [3,] 1 3 [4,] 4 3
Does this involve a straightforward function? Additionally, it must somehow include the names of the row and column:
m e f g a 0 0 1 b > rownames(m) = letters[1:4] > colnames(m) = letters[5:7]