This is a shortcut for x >= left & x <= right
, implemented for local
vectors and translated to the appropriate SQL for remote tables.
Arguments
- x
A vector
- left, right
Boundary values. Both
left
andright
are recycled to the size ofx
.
See also
join_by()
if you are looking for documentation for the between()
overlap
join helper.
Examples
between(1:12, 7, 9)
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE
#> [12] FALSE
x <- rnorm(1e2)
x[between(x, -1, 1)]
#> [1] 0.10323644 0.17250564 -0.72695842 -0.07694410 -0.39868725
#> [6] -0.45262177 -0.01250489 0.17698777 0.48415635 0.95324531
#> [11] 0.58124263 0.93685132 0.20648154 0.07492077 0.47762697
#> [16] -0.28382261 0.62043479 0.49456477 0.60533927 0.62139419
#> [21] -0.62351946 0.38144903 -0.37197127 0.74358522 0.98198728
#> [26] 0.56819077 0.47326244 -0.69839043 -0.04153394 -0.68743254
#> [31] -0.20522673 -0.07945201 -0.10838424 -0.35877666 -0.47895739
#> [36] -0.70516652 0.39482717 -0.08651802 0.09164295 0.80864422
#> [41] 0.83286597 -0.57712023 0.70556833 0.36346849 -0.55914277
#> [46] 0.92117930 0.66356564 0.04751920 -0.58667847 0.06978099
#> [51] 0.45516436 0.07301477 -0.55392880 -0.14267524 -0.42696427
#> [56] -0.74860197 0.01391991 -0.68849653 0.41643015 -0.24374255
#> [61] 0.03921563 -0.72201579 0.10705204 0.17581793 -0.53661794
#> [66] -0.55690686 0.70659457 -0.60487809 -0.69774915 0.71426450
#> [71] 0.75997724 0.55426033 0.74123670 0.26973884 0.96038232
#> [76] -0.45280072 -0.02047234
# 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
#> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr>
#> 1 Leia Orga… 150 49 brown light brown 19 fema…
#> 2 Mon Mothma 150 NA auburn fair blue 48 fema…
#> 3 Watto 137 NA black blue, grey yellow NA male
#> 4 Sebulba 112 40 none grey, red orange NA male
#> 5 Gasgano 122 NA none white, bl… black NA male
#> # ℹ 6 more variables: gender <chr>, homeworld <chr>, species <chr>,
#> # films <list>, vehicles <list>, starships <list>