[R] Still a bug with NA in sd() or var()?

Tony Plate tplate at acm.org
Mon Oct 31 23:30:22 CET 2005


Roger Dungan wrote:
> [snip]>
> There are obvious work-rounds, like
> 
>>sd(x, is.na(x)==F)
> 
> which gives the result (with error message)
> [1] 1.707825
> Warning message:
> the condition has length > 1 and only the first element will be used in:
> if (na.rm) "complete.obs" else "all.obs"
> 

What you are doing here looks very odd to me -- you are passing a vector 
of logicals as the value for the argument na.rm.  This is odd because 
na.rm should be just a single logical value, not a vector of the same 
length as x (hence the warning message).  Only the first element of that 
vector is used, so you are passing essentially a random value.  By luck, 
in your example, the first element was T, which is why you got a value 
of 1.707825 as the result, and not NA.  The rest might fall into place 
when this understanding is cleared up.

-- Tony Plate




More information about the R-help mailing list