[Rd] sd function (PR#11586)

Ben Bolker bolker at ufl.edu
Sat Jun 7 01:48:23 CEST 2008


 <rfolgueira <at> yahoo.com> writes:

> 
> Full_Name: Ramón Folgueira Roque
> Version: 2.7.0
> OS: Windows
> Submission from: (NULL) (200.11.210.98)
> 
> The sd function doesn`t give the same results than older version, when it´s
> applied to a data frame object and the object contains some character data.
> 
> Ex:
> datos=data.frame( )
> fix(datos)
>           Grupo Vel 
>           A     10.1       
>           A     9.8            
>           B     10             
>           B     10             
>           A     9.9           
>           A     10.1          
>           B     NA           
>           A     10            
> 
> sd(datos,na.rm=T)
> 
> ___________________

  This is almost certainly a consequence of the following
change in R 2.7.0:

    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.)
What's happening is that R tries to run sd() on each column.
The first column is coerced to a character, then var() says
there are no non-missing observations.

  This has been discussed (and complained about) previously.
(I'd like to add my vote for reversion of this behavior, because
it screws up one of the examples in my soon-to-be-published
book ... argh.)

  cheers
    Ben Bolker



More information about the R-devel mailing list