Handling Errors in R: Argument is of Length Zero (2 Examples)
On this page, I’ll illustrate how to handle the error message “argument is of length zero” in the R programming language.
Example 1: Replicating the Error Message: Argument is of Length Zero
foo <- character() # Empty character object |
foo <- character() # Empty character object
if(foo == "X") { # Empty character object in if-statement foo } # Error in if (foo == "X") { : argument is of length zero |
if(foo == "X") { # Empty character object in if-statement foo } # Error in if (foo == "X") { : argument is of length zero
Example 2: Solving the Error Message: Argument is of Length Zero
bar <- "X" # Create character object with one value |
bar <- "X" # Create character object with one value
if(bar == "X") { # Non-empty character object in if-statement bar } # "X" |
if(bar == "X") { # Non-empty character object in if-statement bar } # "X"