Jim Robison-Cox <[EMAIL PROTECTED]> writes: > Summary: > If I have a data frame or a matrix where one entire column is NA's, > mean(x, na.rm=T) works on that column, returning NaN, but fails using > apply, in that apply returns NA for ALL columns. > lapply works fine on the data frame. > > If you wonder why I'm building data frames with columns that could be > all missing -- they arise as output of a simulation. The fact that the > entire column is missing is informative in itself. > > > I do wonder if this is a bug.
It isn't... Cutting a long story short: > testcase <- data.frame( x = 1:3, y = rep(NA,3)) > as.matrix(testcase) x y 1 "1" NA 2 "2" NA 3 "3" NA > testcase <- data.frame( x = 1:3, y = as.numeric(rep(NA,3))) > as.matrix(testcase) x y 1 1 NA 2 2 NA 3 3 NA > apply(testcase,2,mean,na.rm=T) x y 2 NaN -- O__ ---- Peter Dalgaard ุster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ 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