[R] Conditional Loop For Data Frame Columns

Rui Barradas ruipbarradas at sapo.pt
Tue Jan 10 02:40:46 CET 2012


Hello,

I believe that the following solves it:

aggregate(SD[, 3:ncol(SD)], by=list(ID), mean)
aggregate(SD[, 3:ncol(SD)], by=list(ID), mean, na.rm=TRUE)

It's the second you want, it will compute the means for groups that aren't
only NA
and return NaN for groups with all values NA.

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Conditional-Loop-For-Data-Frame-Columns-tp4276821p4280750.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list