[R] Change in behaviour of sd()

From: Fiona Johnson <fiona.johnson_at_student.unsw.edu.au>
Date: Tue, 08 Jul 2008 17:38:14 +1000


Hi

I have just upgraded from R2.6.0 to R2.7.1 (running on Windows) and a part of my code that previously ran ok now gives an error. The following is a simple example to demonstrate my problem.

> a <- array(c(1,2,3,4,5,6,rep(NA,6)),dim=c(6,2))
> apply(a,2,sd,na.rm=T)

In R2.6.0 this gives (which is what I would like)

 [1] 1.870829 NA

In R2.7.1 it gives the following error

"Error in var(x, na.rm = na.rm) : no complete element pairs"

As my columns are always either all NA or all numbers, I could get around it by replacing the NA's with 0's but if someone could shed some light on why the behaviour has changed in the new version or a better work around it would be much appreciated. I want to keep the columns of NA's because ultimately I am plotting the results with contour and the NA's refer to grid cells not on land where I don't want to have contours.

Thanks for your help

Fiona


Fiona Johnson
PhD Candidate, UNSW Water Research Centre School of Civil & Environmental Engineering The University of New South Wales, Sydney, NSW, 2052, Australia Email: fiona.johnson (at) student.unsw.edu.au



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 08 Jul 2008 - 07:49:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jul 2008 - 10:31:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive