I imagine this is incredibly simple but I cant seem to find the answer.
I am writing an IF statement but the test is if the object returns a character(0)
value. I am not sure how to deal with character(0)
in the statement.
Assuming Test <- character(0)
or a value:
if (identical(Pols4,character(0))) { print('Empty') } else { print('Not Empty') }
It still does not seem to work.....
If you check length(vec) , we know the length of our vector is also 0, meaning that our vector, vec , is empty.
To check if list is empty in R programming, we have to evaluate the condition that the length of list is zero. Call length() function with this list passed as argument and if the return value is 0 using equal to operator.
To create a character vector in R we can enclose the vector values in double quotation marks but if we want to use a data frame values to create a character vector then as. character function can be used. For example, if we have a data frame df then all the values in the df can form a character vector using as.
Use the identical
function to check this.
a <- character(0) identical(a, character(0)) # returns TRUE identical(a, "") # returns FALSE identical(a, numeric(0)) # returns also FALSE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With