[R] tabulate means & NA

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Jun 20 11:15:56 CEST 2002


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,Christian

tapply(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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list