Back
I received this error message:
Error in if (condition) { : missing value where TRUE/FALSE needed
or
Error in while (condition) { : missing value where TRUE/FALSE needed
What does it mean, and how do I prevent it?
The possible reasons for getting this error are as follows:
For example:
> if(NA){}Error in if (NA) { : missing value where TRUE/FALSE needed> while(NA){}Error in while (NA) { : missing value where TRUE/FALSE needed
> if(NA){}
Error in if (NA) { : missing value where TRUE/FALSE needed
> while(NA){}
Error in while (NA) { : missing value where TRUE/FALSE needed
> if(NULL){}Error in if (NULL) { : argument is of length zero
> if(NULL){}
Error in if (NULL) { : argument is of length zero
if("condition") {}Error in if ("condition") { : argument is not interpretable as logical
if("condition") {}
Error in if ("condition") { : argument is not interpretable as logical
if (c(TRUE, FALSE)) {}NULLWarning message:In if (c(TRUE, FALSE)) { : the condition has length > 1 and only the first element will be used
if (c(TRUE, FALSE)) {}
NULL
Warning message:
In if (c(TRUE, FALSE)) { :
the condition has length > 1 and only the first element will be used
If you want to explore more in R programming then watch this R programming tutorial for beginners:
I once ran into a similar problem while I was checking on a null or empty string:
if (x == NULL || x == '') {
Then, I changed it to something like this:
if (is.null(x) || x == '') {
And the problem was solved.
31k questions
32.8k answers
501 comments
693 users