Skip to content
Back to formatted view

Raw Message

Message-ID: <43669AFE.8020001@acm.org>
Date: 2005-10-31T22:30:22Z
From: Tony Plate
Subject: Still a bug with NA in sd() or var()?
In-Reply-To: <7C773F4D89C83147A023704E9E78103704AC49B2@cantwe.canterbury.ac.nz>

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