This is a shortcut for x >= left & x <= right, implemented
efficiently in C++ for local values, and translated to the
appropriate SQL for remote tables.
between(x, left, right)A numeric vector of values
Boundary values (must be scalars).
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.951654470 -0.500148526 -0.774190616 -0.749629665 0.897234720
#> [6] -0.589779937 0.433198361 -0.844220526 -0.076187318 -0.913003821
#> [11] -0.534018389 0.311334589 -0.276060481 -0.834053124 -0.609274295
#> [16] 0.964125244 0.008047514 -0.439101218 0.436119905 0.953180440
#> [21] -0.829143894 -0.618977321 -0.634389457 -0.367031710 -0.157545284
#> [26] -0.092664225 0.511846418 0.584878189 -0.986764974 0.766573036
#> [31] -0.348041882 0.486015543 0.207125766 0.113070375 0.744350968
#> [36] -0.582422250 0.549168447 0.714366267 0.713360185 0.584145943
#> [41] 0.359160498 0.564863315 0.111520227 0.185465384 0.267037013
#> [46] 0.312366375 0.063833410 0.757557143 0.158213882 0.040379782
#> [51] 0.587687440 -0.928399523 -0.099316520 0.190910203 -0.278959724
#> [56] 0.822934464 0.963741622 0.315657862 -0.270030854 0.943591183
#> [61] -0.574506562 -0.836113889 0.525329514 0.643950819 0.697867179
#> [66] -0.126468910 0.790881146 0.106440942 -0.972265346 -0.578360099
#> [71] 0.062808340 0.418560676
## Or on a tibble using filter
filter(starwars, between(height, 100, 150))
#> # A tibble: 5 × 14
#> name height mass hair_color skin_color eye_color birth_year sex gender
#> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr>
#> 1 Leia Org… 150 49 brown light brown 19 fema… femin…
#> 2 Mon Moth… 150 NA auburn fair blue 48 fema… femin…
#> 3 Watto 137 NA black blue, grey yellow NA male mascu…
#> 4 Sebulba 112 40 none grey, red orange NA male mascu…
#> 5 Gasgano 122 NA none white, bl… black NA male mascu…
#> # … with 5 more variables: homeworld <chr>, species <chr>, films <list>,
#> # vehicles <list>, starships <list>