betwixt: Find values between lower and upper bounds of a range

View source: R/misc.R

betwixtR Documentation

Find values between lower and upper bounds of a range

Description

This is utility function to find values of a vector tha fall between lower and upper bounds specified. The implementation includes a method to optionally ignore certain values and return either a vector of logical indices or a vector of matching values. Inspired by between.

Usage

betwixt(x, lower, upper, ignore = NULL, by = 1, value = FALSE)

Arguments

x

Vector of numeric or date values

lower

The lower bound (inclusive) for the range of values

upper

The upper bound (inclusive) for the range of values

ignore

Vector containing value(s) to exclude; default is NULL

by

Value for increment between lower and upper bounds of the range; default is 1

value

Boolean as to whether the function should return values of x between bounds (TRUE) or a vector of logical indices corresponding to whether or not the value falls between bounds (FALSE); default is FALSE

Value

Depending on the "value" argument, this will either return a vector of values that fall between the lower and upper bounds or a vector of logical vector with TRUE for each index corresponding to a value that falls in the range.

Examples


betwixt(1:12, 7, 9)
betwixt(1:12, 7, 9, value = TRUE)

dates <- seq(as.Date("2000/1/1"), by = "day", length.out = 365)
betwixt(dates,
        lower = as.Date("2000/1/10"),
        upper = as.Date("2000/3/10"),
        by = "day",
        ignore = as.Date("2000/1/25"),
        value = TRUE)

vpnagraj/yawp documentation built on March 31, 2022, 9:56 a.m.