[R] Bug in sd() and var() in handling vectors of NA (R version 2.7.1)?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 29 14:33:48 CEST 2008
There was a bug in 2.6.1 which has since been corrected: there is no need
to report corrected bugs in obsolete versions. Two different ways to
compute the sd of a zero-length vector gave different answers.
This is covered by the following NEWS item for 2.7.0 (version from
R-patched)
o co[rv](use = "complete.obs") now always gives an error if there
are no complete cases: they used to give NA if
method = "pearson" but an error for the other two methods.
(Note that this is pretty arbitrary, but zero-length vectors
always give an error so it is at least consistent.)
Since sd(na.rm=TRUE) and var(na.rm=TRUE) both call cov(use =
"complete.obs"), this applies also to them.
On Tue, 29 Jul 2008, Marisa Laetitia wrote:
> In the previous versions of R (2.6.1), when a vector of NA was given to the functions 'sd' or 'var' with parameter na.rm = TRUE, it used to return NA. Now (2.7.1) it returns an ERROR :
>
>
>
> Example in 2.6.1:
>
>> sd(c(NA, NA, NA, NA), na.rm = TRUE)
>
> [1] NA
>
>
>
> Example in 2.7.1:
>
>> sd(c(NA, NA, NA, NA), na.rm = TRUE)
>
> Error in var(x, na.rm = na.rm) : paires d'?l?ments incompl?tes
>
>
>
> We are actually wondering if it is a bug to report, or if we have to manage it in our own R scripts.
>
>
>
> Thanks a lot, best regards,
>
>
>
> Laetitia
>
>
>
>
>
>
>
>
>
> ************************************************************************************
> This footnote confirms that this email message has been scanned by
> PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses.
> ************************************************************************************
>
>
>
> [[alternative HTML version deleted]]
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list