-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Roger Dungan
Sent: Monday, October 31, 2005 1:24 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Still a bug with NA in sd() or var()?
Dear R-users,
Running R 2.1.1 in WindowsXP, there seems to be a 'bug' in sd()
If
give
Error in var(x, na.rm = na.rm) : missing observations in cov/cor
There are obvious work-rounds, like
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"
or
y<-subset(x, is.na(x)==F)
sd(y)
[1] 1.707825
Am I missing something, or is this a problem with sd()? Why
does mean(x)
give a simple NA, but var(x) requires some additional work? There was
some previous discussion in r-help about this for R v 1.6.0, with
mention of a fix for 1.6.1.
Dr Roger Dungan
School of Biological Sciences
University of Cantebury
Christchurch, New Zealand
ph +64 3 366 7001 ext. 4848
fax +64 3 364 2590