[R-SIG-Mac] NA handling in 2.7.0 versus 2.6.2 for SD

Simon Urbanek simon.urbanek at r-project.org
Tue Apr 22 19:03:45 CEST 2008


On Apr 22, 2008, at 12:48 PM, William Revelle wrote:

> Hi,
> When comparing how R2.7.0 handles missing values  I discovered that
> it differs from 2.6.2 (at least for the sd function).   In
> particular, if a column of a matrix is all NA, sd in 2.7.0 throws an
> error while in 2.6.2 it just returns NA for that column.  Is this
> intentional?
>

Yes, please see NEWS:

     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.)

Also this is not Mac-specific so I wonder why ask here?

Cheers,
Simon


>> x <- matrix(1:50,ncol=5)
>> sd(x)
> [1] 3.027650 3.027650 3.027650 3.027650 3.027650
>>  x[,1] <- NA
>> sd(x,na.rm=TRUE)
> Error in var(x, na.rm = na.rm) : no complete element pairs
>
>
>
> R version 2.7.0 RC (2008-04-21 r45421)
> i386-apple-darwin8.10.1
>
> locale:
> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
> compare this to version 2.6.2
>> x <- matrix(1:50,ncol=5)
>> sd(x)
> [1] 3.027650 3.027650 3.027650 3.027650 3.027650
>
>>  x[,1] <- NA
>> sd(x,na.rm=TRUE)
> [1]       NA 3.027650 3.027650 3.027650 3.027650
>
>> sessionInfo()
> R version 2.6.2 (2008-02-08)
> i386-apple-darwin8.10.1
>
> locale:
> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>
> Thanks for all the great work.  Sorry not to have detected this  
> sooner.
>
> Bill
>
>
> -- 
> William Revelle		http://personality-project.org/revelle.html
> Professor			http://personality-project.org/personality.html
> Department of Psychology             http://www.wcas.northwestern.edu/psych/
> Northwestern University	http://www.northwestern.edu/
> Use R for statistics:                          http://personality-project.org/r
>
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
>
>



More information about the R-SIG-Mac mailing list