Re: [R] A faster way to aggregate?

From: Dieter Menne <dieter.menne_at_menne-biomed.de>
Date: Tue 05 Jul 2005 - 01:43:11 EST

Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:

> Note that you did not actually try my suggestion which was rowsum,
> not colMeans.

Mea culpa, I was hooked by rowSums, and so I was did not get aware of the grouping facility of rowsum().  

> The following solution based on rowsum is more than
> an order of magnitude faster than any of the solutions in your
> posts:
>
> sc1 <- as.matrix(sc[,-1])
> is.na.sc1 <- is.na(sc1)
> x1 <- rowsum(ifelse(is.na.sc1, 0, sc1), group)
> xx <- rowsum(1-is.na.sc1, group)
> res <- floor(100*x1/xx)

Thanks a lot.

Dieter



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 05 01:47:20 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:11 EST