between()
utilizes data.table::between()
in the background
between(x, left, right)
A numeric vector
Boundary values
df <- data.table(
x = 1:5,
y = 1:5
)
# Typically used in a filter()
df %>%
filter(between(x, 2, 4))
#> # A tidytable: 3 × 2
#> x y
#> <int> <int>
#> 1 2 2
#> 2 3 3
#> 3 4 4
df %>%
filter(x %>% between(2, 4))
#> # A tidytable: 3 × 2
#> x y
#> <int> <int>
#> 1 2 2
#> 2 3 3
#> 3 4 4
# Can also use the %between% operator
df %>%
filter(x %between% c(2, 4))
#> # A tidytable: 3 × 2
#> x y
#> <int> <int>
#> 1 2 2
#> 2 3 3
#> 3 4 4