Hi, i have some problems to get means, but the data have got NA's which should not be replaced or delete ! tapply(data,var,mean) # makes me problem,because when one value is NA mean is NA,too. Another attempt is this, because the summary does what i want , but is not subsetable to summary[4] if i use tapply,table and the the function below gives me again all means as NA ? xmean <- function (var) { summary(var)[4] } apply(data,2,xmean) Thanks for any suggestion & regards,Christian -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Christian Schulz <c.schulz at metrinomics.de> writes:> Hi, > i have some problems to get means, but the data have got > NA's which should not be replaced or delete ! > > tapply(data,var,mean) # makes me problem,because when one value is > NA mean is NA,too. > > Another attempt is this, because the summary does what i want , but > is not subsetable to summary[4] if i use tapply,table and the the > function below gives me > again all means as NA ? > > xmean <- function (var) { > summary(var)[4] } > apply(data,2,xmean) Thanks for any suggestion & regards,Christiantapply(data,var,mean, na.rm=TRUE) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Christian Schulz wrote:> > i have some problems to get means, but the data have got > NA's which should not be replaced or delete ! > > tapply(data,var,mean) # makes me problem,because when one value is > NA mean is NA,too.You may want to have a look at the mean help page (?mean) and add `na.rm = TRUE' to the `tapply' call, i.e. tapply(data, var, mean, na.rm=TRUE) You might also want to read the help pages for `na.action', `na.omit', `na.fail' on how methods can be tuned to deal with missing values. Greets, Diego Kuonen -- Dr. ?s sc. Diego Kuonen CEO & Applied Statistician Statoo Consulting, PO Box 107, 1015 Lausanne, Switzerland + Have you ever been Statooed? http://www.statoo.info + + Free Statooed newsletters: http://lists.statoo.com + -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._