[R] NA and NaN question

Pascal A. Niklaus pniklaus at ethz.ch
Wed Jan 7 12:08:29 CET 2009


Hi all,

I ran into a problem in some of my code that could be traced back to 'mean' 
sometimes returning NA and sometimes NaN, depending on the value of na.rm:

> mean(c())
[1] NA

> mean(c(NA),na.rm=T)
[1] NaN

However, I don't understand the reasoning behind this and would appreciate and 
explanation. 

I understand that the mean of an empty vector is not definied, but I don't 
understand why it matters whether the vector was empty from the beginning or 
only after removing the NAs.

Pascal Niklaus




More information about the R-help mailing list