Chuck, thanks a lot, this is a very good starting point. G.
On Sat, Jan 12, 2008 at 01:08:11PM -0800, Charles C. Berry wrote: [...] > Gabor, > > Try this. Order the matrix rows, conpare adjacent rows, and run length > encode the logical vector of comparisons. Decode the rle() result to get > the counts, use the logical vector comparing adjacent rows to identify the > unique rows, and cbind() them together. Like this: > > count.rows <- > function(x) > { > order.x <- do.call(order,as.data.frame(x)) > equal.to.previous <- > rowSums(x[tail(order.x,-1),] != x[head(order.x,-1),])==0 > tf.runs <- rle(equal.to.previous) > counts <- c(1, > unlist(mapply( function(x,y) if (y) x+1 else (rep(1,x)), > tf.runs$length, tf.runs$value ))) > counts <- counts[ c(diff(counts) <= 0, TRUE ) ] > unique.rows <- which( c(TRUE, !equal.to.previous ) ) > cbind( counts, x[order.x[ unique.rows ], ,drop=F] ) > } > > HTH, > > Chuck > [...] -- Csardi Gabor <[EMAIL PROTECTED]> UNIL DGM ______________________________________________ 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.