This is a shortcut for x >= left & x <= right
, implemented for local
vectors and translated to the appropriate SQL for remote tables.
between(x, left, right)
A logical vector the same size as x
.
x
, left
, and right
are all cast to their common type before the
comparison is made.
join_by()
if you are looking for documentation for the between()
overlap
join helper.
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.93536319 0.17648861 0.24368546 0.11203808 -0.13399701 -0.27923724
#> [7] -0.31344598 0.07003485 -0.63912332 -0.04996490 -0.25148344 0.44479712
#> [13] 0.04653138 0.57770907 0.11819487 0.86208648 -0.24323674 -0.20608719
#> [19] 0.01917759 0.02956075 0.54982754 -0.36122126 0.21335575 -0.66508825
#> [25] -0.24589641 -0.97585062 0.13167063 0.48862881 0.28415034 0.23669628
#> [31] 0.52390979 0.60674805 -0.10993567 0.17218172 -0.09032729 0.74879127
#> [37] 0.55622433 -0.54825726 -0.15569378 0.43388979 -0.38195111 0.42418757
#> [43] -0.03810289 0.48614892 -0.35436116 0.94634789 -0.29664002 -0.38721358
#> [49] -0.78543266 -0.79554143 -0.69053790 -0.55854199 -0.53666333 0.22712713
#> [55] 0.97845492 -0.20888265 0.25853729 -0.44179945 0.56859986 0.42485844
#> [61] 0.24940178 0.44945378 0.42656655 0.10758399 0.02229473 0.60361101
#> [67] -0.26265057 -0.52826408 0.19214942
# 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…
#> # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>,
#> # vehicles <list>, starships <list>