R -Error: “argument is of length zero” in an expression


This is an error which happens when you compare something to NULL.
When you compare some values in the R the result is expected to be either TRUE or FALSE.
However the result of the expression is not defines then R gives output as logical (0) and if this expression is used in IF condition, whenever the condition encounters logical (0) it will throw error as “Error in if (*expression) { : argument is of length zero”.
Below examples will make it clearer:
                                                                                                 

 

 

To avoid this error please make sure that the expression never returns logical (0) OR logical (1).

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.