I'm trying to drive command where i would get values from X which are between variables y and z. I didn't find it from my R quide, does anyone remember? like x[y,z]
I've already tried cut(), between, min(y) max(z), nothing of these haven't worked.
I'm trying to drive command where i would get values from X which are between variables y and z. I didn't find it from my R quide, does anyone remember? like x[y,z]
I've already tried cut(), between, min(y) max(z), nothing of these haven't worked.
Does this answer:
x <- 1:10
x
[1] 1 2 3 4 5 6 7 8 9 10
y <- 3
z <- 7
x[x>=y & x <=z]
[1] 3 4 5 6 7
You can write x[x > y & x < z]
.
If you use data.table, it comes with a nice %between%
operator and between()
function so you can write x[x %between% c(y, z)]
if y
and z
are atomic vectors, or x[between(x, y, z)]
if they are vector of the same length as x
.
dplyr has also a betweeen()
function.