I'm using the grep
function in R to check if a conditional regular expression is met.
What I have is this: grep(expression, string)
where an example might be
value= grep("\\s[A-z]", " ")
value
which outputs
integer(0)
What I want to be able to do is check is if value == integer(0)
and
return TRUE if value
is integer(0)
return FALSE if value
is not integer(0)
Is there a way to do this in R? If there are alternatives, I am open to them. For example, grep might have an option to output the result as a logical value,
TRUE and FALSE, or
0 and 1 or something related.
You can use identical
which is the safe and reliable way to test two objects for being exactly equal (from the docs):
value = integer(0)
identical(value, integer(0))
# [1] TRUE
Or do the following check:
is.integer(value) && length(value) == 0
# [1] TRUE
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