Re: [R] tapply and NA value

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.ac.be>
Date: Fri 25 Mar 2005 - 20:52:57 EST

you should look at the 'na.rm=FALSE' argument of '?mean()', i.e.,

x <- rnorm(100); x[sample(100, 10)] <- NA f <- sample(letters[1:5], 100, TRUE)
###############
tapply(x, f, mean)
tapply(x, f, mean, na.rm=TRUE)

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


> Hi,
> I'm writing for a little help.
> I have a dataframe with same NA value and I'd like to obtain the
> means of the
> value of a coloumn grouped by the levels of a factor coloumn of the
> datframe.
> I'm using the function "tapply" but I see that if only a NA value is
> present
> the result is NA.
> There is an option to have the correct result or I must use an other
> function?
>
> Thanks of all
> Leonardo
> --
> Leonardo Lami
> lami@faunalia.it www.faunalia.it
> Via Colombo 3 - 51010 Massa e Cozzile (PT), Italy Tel:
> (+39)349-1310164
> GPG key @: hkp://wwwkeys.pgp.net http://www.pgp.net/wwwkeys.html
> https://www.biglumber.com
>
> ______________________________________________
> 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
>



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 Received on Fri Mar 25 20:52:57 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST