[R] sd(NA)

Roy Mendelssohn Roy.Mendelssohn at noaa.gov
Fri Aug 22 21:21:58 CEST 2008


Hi All:

This was discussed in the R-developers list   (see the thread  
starting at http://tolstoy.newcastle.edu.au/R/e3/devel/ 
07/12/0560.html).  It has to do with the behavior of sd() when the  
entire vector is NA.  The behavior has changed between 2.6 and 2.7.1  
as follows:

Run in Version 2.7.1
 > tt<-rep(NA, 10)
 > mean(tt, na.rm=T)
[1] NaN
 >sd(tt, na.rm=T)
Error in var(x, na.rm=na.rm) : no complete element pairs

Run in Version 2.6.1
 > tt<-rep(NA, 10)
 > mean(tt, na.rm=T)
[1] NaN
 >sd(tt, na.rm=T)
Na

If I understand the discussion, 2.7.1 fails because 'rm=T' removes  
the NA's so that it is now empty. What I have been unable to find in  
any of the mail lists is how you are suppose to program this  in  
2.7.1. when you are looping through a large number of  
"variables"  (we have  time series on a grid and are calculating the  
mean and sd of the time series at each grid point).

Any suggestions much appreciated.

-Roy M.

**********************
"The contents of this message do not reflect any position of the U.S.  
Government or NOAA."
**********************
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
1352 Lighthouse Avenue
Pacific Grove, CA 93950-2097

e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address)
voice: (831)-648-9029
fax: (831)-648-8440
www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected"



More information about the R-help mailing list