This is a shortcut for x >= left & x <= right
.
Examples
between(1:12, 7, 9)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE
x <- rnorm(1e2)
x[between(x, -1, 1)]
#> [1] 0.255317055 -0.005571287 0.621552721 -0.247325302 -0.244199607
#> [6] -0.282705449 -0.553699384 0.628982042 0.512426950 -0.522012515
#> [11] -0.052601910 0.542996343 -0.914074827 0.468154420 0.362951256
#> [16] 0.737776321 -0.097445104 -0.935847354 -0.015950311 -0.826788954
#> [21] 0.935363190 0.176488611 0.243685465 0.112038083 -0.133997013
#> [26] -0.279237242 -0.313445978 0.070034850 -0.639123324 -0.049964899
#> [31] -0.251483443 0.444797116 0.046531380 0.577709069 0.118194874
#> [36] 0.862086482 -0.243236740 -0.206087195 0.019177592 0.029560754
#> [41] 0.549827542 -0.361221255 0.213355750 -0.665088249 -0.245896412
#> [46] -0.975850616 0.131670635 0.488628809 0.284150344 0.236696283
#> [51] 0.523909788 0.606748047 -0.109935672 0.172181715 -0.090327287
#> [56] 0.748791268 0.556224329 -0.548257264 -0.155693776 0.433889790
#> [61] -0.381951112 0.424187575 -0.038102895 0.486148920 -0.354361164
#> [66] 0.946347886 -0.296640025