# how to extract specific subscript of a matrix

4 messages
Open this post in threaded view
|

## how to extract specific subscript of a matrix

 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 implement idea? Thanks! Best, Jinsong ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: how to extract specific subscript of a matrix

 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 <[hidden email]> wrote: >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 implement idea? Thanks! > >Best, >Jinsong > >______________________________________________ >[hidden email] mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help>PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code. -- Sent from my phone. Please excuse my brevity. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.