Hello,
The function bwlabel() in the Bioconductor package EBImage, extracts the
connected components of an image. Denoting your binary matrix by x, the
following code gives you the first 10 largest clusters (in size).
> library(EBImage)
> y = bwlabel(x)
> sort(table(y), dec=TRUE)[1:10]
See http://www.bioconductor.org/packages/release/bioc/html/EBImage.html
how to download/install EBImage.
Best regards,
Greg
---
Gregoire Pau
EMBL Research Officer
http://www.ebi.ac.uk/~gpau/
Sylvain Sardy wrote:> Hi,
>
> on a lattice, I have binary 0/1 data. 1s are rare and may form clusters.
> I would like
> to know the size/length of largest cluster. Any help warmly welcome,
>
> Sylvain.
>
> ______________________________________________
> 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.