Skip to content

tapply and NA value

4 messages · Leonardo Lami, Dimitris Rizopoulos, Ales Ziberna

#
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
#
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


----- Original Message ----- 
From: "Leonardo Lami" <lami at faunalia.it>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, March 25, 2005 10:35 AM
Subject: [R] tapply and NA value
#
I am not really sure what you mean. If I understand you correctly, than all 
ylu have to do is to give additiona parameter to tapply, na.rm=TRUE,

tapply(...., na.rm=TRUE)

However as I already said, I'm not sure what you did and what is the 
problem. Plese provide the code that did not work, possibly with a workable 
example, as the posting guide suggests:
"PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html"

I hope this helps in anyway,
Ales Ziberna


----- Original Message ----- 
From: "Leonardo Lami" <lami at faunalia.it>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, March 25, 2005 10:35 AM
Subject: [R] tapply and NA value
#
Thanks very much!
Best of all,
Leonardo


Alle 10:52, venerd? 25 marzo 2005, Dimitris Rizopoulos ha scritto: