How can I apply the AND & or OR| operators to a logical vector in R?
For example:
a <- c(FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE)
Is there a simple way to
TRUE? Like putting an & between each element:
FALSE TRUE? Like putting a | between each element
TRUEallTrue <- all(a)
anyTrue <- any(a)
The documentation for these functions is linked from help("&") or help("|").
all and any are exactly what you are after, alternatively:
sum(a)==length(a) # Are all elements TRUE?
sum(a)>0 # Are any elements 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