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