On 22/08/2018 10:33 AM, Ivan Calandra wrote:
Dear useRs,

I have just noticed that when input is only NA with na.rm=TRUE, mean()
results in NaN, whereas median() and sd() produce NA. Shouldn't it all
be the same? I think NA makes more sense than NaN in that case.

The mean can be defined as sum(x)/length(x), so if x is length 0, you get 0/0 which is NaN.

median(x) is documented in its help page to give NA for x of length 0.

sd(x) is documented to give an error for such x and NA for length 1, but it gives NA for both.

Duncan Murdoch

x <- c(NA, NA, NA) mean(x, na.rm=TRUE) [1] NaN median(x, na.rm=TRUE) [1]
NAsd(x, na.rm=TRUE) [1] NA

Thanks for any feedback.

Best,
Ivan


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to