Hey, I had the same question concerning the sd calculation and I got the following solution:
list <- split(list, class_vec) list <- lapply(list, function(x) do.call('rbind', x)) my.mean <- lapply(ret, FUN = function(x) { t <- as.matrix(x) rm <- as.matrix(apply( t, 1, FUN = function(w) { length(which(is.na(w) == TRUE)) } )) t <- matrix(t[rm == 0,], ncol=7) # I had to do the 2 lines above to remove rows belonging to a class but containing NA values... (cannot exclude) if(nrow(t) > 1) { apply(t, 2, mean) } else { if(nrow(t) == 1) { as.vector(t) } else { NA } } }) Probably, there is a simpler solution to remove the NA rows, but it works ;); also with "sd". Ciao, Antje 8rino-Luca Pantani schrieb: >> Hi Jim, >> that's exactly what I'm looking for. Thank you so much. I think, I >> should look for some further documentation on list handling. > I think I will do the same................... > Thanks to Jim I learned "textConnection" and "rowMeans". > > Jim, could you please go a step further and tell me how to use lapply to > calculate > the sd instead of the mean of the same items? > I mean > sd(-0.6442149 0.02354036 -1.40362589) > sd(-1.1829260 1.17099178 -0.046778203) > sd(-0.2047012 -1.36186952 0.13045724) > etc > > x <- read.table(textConnection(" v1 v2 v3 v4 v5 v6 v7 v8 > NA -0.6442149 0.02354036 -1.40362589 -1.1829260 1.17099178 > -0.046778203 NA > NA -0.2047012 -1.36186952 0.13045724 2.1411553 0.49248118 > -0.233788840 NA > NA -1.1986041 -0.42197792 -0.84651458 -0.1327081 -0.18690065 > 0.443908897 NA > NA -0.2097442 1.50445971 1.57005071 -0.1053442 1.50050976 > -1.649740180 NA > NA -0.7343465 -1.76763996 0.06961015 -0.8179396 -0.65552410 > 0.003991354 NA > NA -1.3888750 0.53722404 0.25269771 -1.2342698 -0.01243247 > -0.228020092 NA"), header=TRUE) > > > > > ______________________________________________ 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 and provide commented, minimal, self-contained, reproducible code.