Thanks Gabor. Nice solution. Marc
On Thu, 2007-11-15 at 12:35 -0500, Gabor Grothendieck wrote: > We can append a row of 0's to handle that case: > > with(rle(as.vector(rbind(prova, 0))), table(lengths[values == 1])) > > > > On Nov 15, 2007 11:36 AM, Marc Schwartz <[EMAIL PROTECTED]> wrote: > > Ah...OK. I misunderstood then. I thought that you wanted the number of > > runs of 1's in each column. > > > > This is actually easier, _if_ there is not an overlap of 1's from the > > end of one column to the start of the next column: > > > > res <- rle(as.vector(prova)) > > > > > res > > Run Length Encoding > > lengths: int [1:11] 2 2 2 2 3 3 5 4 2 1 ... > > values : int [1:11] 3 1 3 1 3 1 3 1 3 1 ... > > > > > table(res$lengths[res$values == 1]) > > > > 1 2 3 4 > > 1 2 1 1 > > > > > > HTH, > > > > Marc > > <snip> ______________________________________________ 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.