0

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.

Tove S
  • 1
  • 1
  • Welcome to Stack Overflow! What class of object is X? Is it a daframe, a vector? When you say variables y and x, do you mean values y and z? Please see how to make a good question in R: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – LuizZ Nov 28 '20 at 17:13

2 Answers2

0

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
Karthik S
  • 11,348
  • 2
  • 11
  • 25
0

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.

Elio Campitelli
  • 1,408
  • 1
  • 10
  • 20