Dear all, I have a binary matrix 0 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 I want to find the location of all the square and rectangular 1 blocks, like First block in row=2, col=1 to row=3, col=3. Second block in row=5, col=4, to row=6, col=5. How can I find such blocks of 1? Thanks: John
you can find it by use of indexing with setting 1=T and 0=False in your global environment of R. On Fri, Jan 10, 2014 at 12:32 PM, email <email8889@gmail.com> wrote:> Dear all, > > I have a binary matrix > > 0 0 0 0 0 > 1 1 1 0 0 > 1 1 1 0 0 > 0 0 0 0 0 > 0 0 0 1 1 > 0 0 0 1 1 > > I want to find the location of all the square and rectangular 1 blocks, > like > > First block in row=2, col=1 to row=3, col=3. > Second block in row=5, col=4, to row=6, col=5. > > How can I find such blocks of 1? > > Thanks: > John > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]
What would you like to get from the following? 0 1 0 0 0 1 1 1 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 0 1 1 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of email > Sent: Thursday, January 09, 2014 11:03 PM > To: r-help at r-project.org > Subject: [R] locate pattern in matrix > > Dear all, > > I have a binary matrix > > 0 0 0 0 0 > 1 1 1 0 0 > 1 1 1 0 0 > 0 0 0 0 0 > 0 0 0 1 1 > 0 0 0 1 1 > > I want to find the location of all the square and rectangular 1 blocks, like > > First block in row=2, col=1 to row=3, col=3. > Second block in row=5, col=4, to row=6, col=5. > > How can I find such blocks of 1? > > Thanks: > John > > ______________________________________________ > R-help at r-project.org mailing list > 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.