Skip to content

Mean and var inconsistency (PR#2094)

1 message · Kevin.Wright@pioneer.com

#
Full_Name: Kevin Wright
Version: 1.5.1
OS: Windows 95
Submission from: (NULL) (170.54.59.160)


Originally posted to r-devel, but after thinking about it more decided that this
is a bug.  I encountered an unexpected difference in the way that mean and var
work:
[1] NaN
Error in var(numeric(0)) : `x' is empty 

Looking into this, I discovered in mean.default that sum(x)/n 
evaluates as
[1] NaN 

The function var seems to evaluate this:
Error: `x' is empty 

One possible fix would be to modify var to check that the length of x is greater
than 0, otherwise return NaN/NA.  

Just for your information (not necessarily the desirable answer), in S-Plus
2000:
NA
NA



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._