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:
[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,
Not so, it is well-defined as 0/0 = NaN.
but I don't
understand why it matters whether the vector was empty from the beginning
You didn't try that case: mean(numeric(0)) is also NaN. The issue is that
[1] "NULL"
is not numeric (not evan a vector), and so mean() of it is undefined.
> or only after removing the NAs.