[R] Error message: missing value where logical needed

Haynes, Maurice (NIH/NICHD) haynesm at cfr.nichd.nih.gov
Wed Nov 27 15:39:04 CET 2002


Dear all,

I often import data sets from other programs that contain user defined
missing values.  As an example consider a variable MXPLOCO with a user
defined missing value of as -9.

> summary(MXPLOCO)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
 -9.000   4.750   5.000   5.349   6.000   8.500   2.000

The following command successfully converts the value -9 to NA.  However, an
error message is also returned:

> for(i in 1:length(MXPLOCO)) {
+     if(MXPLOCO[i] == c(-9, NA)) MXPLOCO[i] <- NA
+     }
Error in if (MXPLOCO[i] == c(-9, NA)) MXPLOCO[i] <- NA : 
        missing value where logical needed
> summary(MXPLOCO)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
   4.00    5.00    5.00    5.54    6.00    8.50    3.00 

What is the meaning of the error message, and how can I resolve the error?

Thanks,

Maurice

O. Maurice Haynes, Applied Statistician
National Institute of Child Health and Human Development
Child and Family Research Section
6705 Rockledge Drive
Bethesda, MD  20892
Voice: 301-496-8180
Fax: 301-496-2766
E-Mail: mh192j at nih.gov


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list