[R] locate pattern in matrix

email email8889 at gmail.com
Fri Jan 10 08:02:59 CET 2014


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



More information about the R-help mailing list