in_range: Test if values is in a given range

Description Usage Arguments Examples

View source: R/in_range.R

Description

Checks either whether both extrema are in the given range, or if each individual value is.

Usage

1
in_range(x, lower, upper, inc = c(TRUE, TRUE), na = NA)

Arguments

x

any atomic or vector-like object

lower

lower range

upper

upper range

inc

logical vector of length one or two; should the lower and upper ranges, respectively, be considered inclusive?

na

should NAs in x return TRUE, FALSE, NA, or something else?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
in_range(c(1:3, NA), 1, 4, na=NA)

in_range(1:4, 1, 4)
in_range(matrix(1:4, 2), 1, 4)

in_range(1:4, 1, 4, inc=1:0)
in_range(1:4, 1, 4, inc=0:1)
in_range(1:4, 1, 4, inc=0)

x <- as.Date(0:3, origin="2000-01-01")
in_range(x, "2000-01-01", "2000-01-04")

in_range(letters[1:4], "a", "d", inc=1:0)
in_range(letters[1:4], "a", "da", inc=1:0)

# no upper range
in_range(c(10^rnorm(9), NA), 0, NA)
in_range(c(10^rnorm(9), NA), 0, NA, na=TRUE)

AkselA/R-ymse documentation built on March 21, 2020, 9:52 a.m.