2

I'm starting to learn R, as it's needed for work. I have never done statistical work, so I'm a bit lost.

I'm looking to get the value of x between two numbers.

So, for example, the range is 3:7 I need to print 4,5,6

I have tried

    x <- 3:7
    x[x>3 && x<7]

and

x <- 3
v <- 7
cbind(x, findInterval(x, v))

Any advice/guidelines

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
  • 2
    In the first you have a typo, there's a `x`missing. And use the vectorized and, `&`. `x[x > 3 & x < 7]`. PS: read the file `R-intro.pdf` that comes with your installation of `R`. – Rui Barradas Sep 23 '17 at 13:46
  • Thanks very much @RuiBarradas –  Sep 23 '17 at 14:01

1 Answers1

1

An option is between from data.table

x[data.table::between(x, 3, 7, incbounds = FALSE)]
#[1] 4 5 6
akrun
  • 874,273
  • 37
  • 540
  • 662