This convenience function tests whether elements of a numeric vector x lie
within a specified numeric interval range. It is similar to
data.table::between(), except that it allows a more flexible specification
of open and closed interval boundaries. An infix operator %inrange% is
provided, which includes the lower and excludes the upper bound.
Value
A logical vector of the same length as x, indicating TRUE for
elements within the specified interval.
Examples
x <- seq(0, 5, 0.5)
x %inrange% c(1, 2)
#> [1] FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
identical(inrange(x, c(1, 2), closed_interval = c(TRUE, FALSE)), x %inrange% c(1, 2))
#> [1] TRUE
inrange(x, c(1, 2), closed_interval = c(TRUE, TRUE))
#> [1] FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE