I would like to ask if there is a way to check for example
c(13, 20, 1, 5, 40, 15, 6, 8)
is within a range e.g. > 5
and <= 30
will give output like below:
[1] TRUE TRUE FALSE FALSE TRUE TRUE TRUE
Isn't it just this?
x <- c(13, 20, 1, 5, 40, 15, 6, 8)
x > 5 & x <= 30
#[1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE
We can also use between
from dplyr
or data.table
but this includes upper and lower boundaries so we can do
dplyr::between(x, 6, 31)
#[1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE
Or
data.table::between(x, 6, 31)
First of all you omitted a FALSE in your expected result. But you can achieve that by doing this :
c <- c(13, 20, 1, 5, 40, 15, 6, 8)
a <- c > 5 & c <= 30
print(a)