Error in if/while (condition) {: missing Value where TRUE/FALSE needed

后端 未结 3 623
[愿得一人]
[愿得一人] 2020-11-21 23:19

I received this error message:

Error in if (condition) { : missing value where TRUE/FALSE needed

or

Error in while (conditi         


        
3条回答
  •  遥遥无期
    2020-11-21 23:53

    The evaluation of condition resulted in an NA. The if conditional must have either a TRUE or FALSE result.

    if (NA) {}
    ## Error in if (NA) { : missing value where TRUE/FALSE needed
    

    This can happen accidentally as the results of calculations:

    if(TRUE && sqrt(-1)) {}
    ## Error in if (TRUE && sqrt(-1)) { : missing value where TRUE/FALSE needed
    

    To test whether an object is missing use is.na(x) rather than x == NA.


    See also the related errors:

    Error in if/while (condition) { : argument is of length zero

    Error in if/while (condition) : argument is not interpretable as logical

    if (NULL) {}
    ## Error in if (NULL) { : argument is of length zero
    
    if ("not logical") {}
    ## Error: argument is not interpretable as logical
    
    if (c(TRUE, FALSE)) {}
    ## Warning message:
    ## the condition has length > 1 and only the first element will be used
    

提交回复
热议问题