Re: [R] how to extract specific subscript of a matrix

2020-06-27 Thread peter dalgaard
For that, it is more straightforward to use which(M==1, arr.ind=TRUE) However, the desired output has 8 indices, not 12. I don't see what the desired pattern is... - pd > On 11 Jun 2020, at 03:01 , Jeff Newmiller wrote: > > M <- matrix(c(2,2,rep(1,12), 2), nrow = 5,byrow = FALSE) > ix <- exp

Re: [R] how to extract specific subscript of a matrix

2020-06-10 Thread Rasmus Liland
On 2020-06-10 18:01 -0700, Jeff Newmiller wrote: > On June 10, 2020 5:29:10 PM PDT, Jinsong Zhao wrote: > > > > (3,1), (5,1), (5,2), (4,2), (4,3), (1,3), (1,2), (3,2) > > M <- matrix(c(2,2,rep(1,12), 2), nrow = 5,byrow = FALSE) > ix <- expand.grid( r = seq.int( nrow( M ) ) > , c

Re: [R] how to extract specific subscript of a matrix

2020-06-10 Thread Jeff Newmiller
M <- matrix(c(2,2,rep(1,12), 2), nrow = 5,byrow = FALSE) ix <- expand.grid( r = seq.int( nrow( M ) ) , c = seq.int( ncol( M ) ) ) ix[ 1 == c(M), ] On June 10, 2020 5:29:10 PM PDT, Jinsong Zhao wrote: >Hi there, > >I have a matrix similar as: > >M <- matrix(c(2,2

[R] how to extract specific subscript of a matrix

2020-06-10 Thread Jinsong Zhao
Hi there, I have a matrix similar as: M <- matrix(c(2,2,rep(1,12), 2), nrow = 5,byrow = FALSE) I hope to get the border subscript of the block with value 1. In the above example, I hope to get: (3,1), (5,1), (5,2), (4,2), (4,3), (1,3), (1,2), (3,2) Is there any function can do that? or any