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)

Arguments

x

A numeric vector of values

left, right

Boundary values (must be scalars).

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.71128732  0.67638957 -0.23276176  0.63747287 -0.68326687 -0.97967535
#>  [7] -0.46251911  0.74786883 -0.80534353  0.77599004  0.70359786  0.71540139
#> [13]  0.40152349  0.40427794 -0.77705556 -0.28045548  0.29738725 -0.23564615
#> [19]  0.04433469 -0.32849189  0.46205231  0.69362435 -0.70859443 -0.20889688
#> [25]  0.35227917 -0.77928540  0.70005531  0.11759261 -0.28362275  0.49790884
#> [31]  0.38624909  0.71752478  0.13191018 -0.92066340  0.26726762 -0.23854626
#> [37] -0.78447669 -0.82776894  0.94433756 -0.63969296 -0.21714460  0.57991478
#> [43] -0.95260348 -0.96767371  0.79245114 -0.93697260  0.86130054  0.62163991
#> [49]  0.48472168 -0.44727427  0.54609708  0.24288873  0.16851210  0.23906467
#> [55]  0.23632142 -0.25911917  0.64904570  0.84197042  0.26416593  0.09731070
#> [61] -0.98868279

## Or on a tibble using filter
filter(starwars, between(height, 100, 150))
#> # A tibble: 5 x 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 Or…    150    49 brown      light      brown             19 fema… femini…
#> 2 Mon Mot…    150    NA auburn     fair       blue              48 fema… femini…
#> 3 Watto       137    NA black      blue, grey yellow            NA male  mascul…
#> 4 Sebulba     112    40 none       grey, red  orange            NA male  mascul…
#> 5 Gasgano     122    NA none       white, bl… black             NA male  mascul…
#> # … with 5 more variables: homeworld <chr>, species <chr>, films <list>,
#> #   vehicles <list>, starships <list>