between: Detect if values fall within a range

View source: R/between.R

betweenR Documentation

Detect if values fall within a range

Description

This is essentially a shortcut for x >= left & x <= right, but it also retains the size of x and casts both left and right to the type of x before making the comparison.

Usage

between(x, left, right, ..., bounds = "[]")

Arguments

x

A vector

left, right

Boundary values. Both left and right are recycled to the size of x and are cast to the type of x.

...

These dots are for future extensions and must be empty.

bounds

One of "[]", "[)", "(]", or "()", which defines whether the boundary is inclusive (with [ or ]) or exclusive (with ( or )).

Value

A logical vector the same size as x.

Examples

between(c(1:10, NA), 4, 6)
between(letters, "d", "j")

today <- Sys.Date()
between(today, today - 1, today + 1)

r-lib/funs documentation built on May 14, 2022, 2:28 a.m.