in_range {validate} | R Documentation |
Check variable range
Description
Test wether a variable falls within a range.
Usage
in_range(x, min, max, ...)
## Default S3 method:
in_range(x, min, max, strict = FALSE, ...)
## S3 method for class 'character'
in_range(x, min, max, strict = FALSE, format = "auto", ...)
Arguments
x |
A bare (unquoted) variable name. |
min |
lower bound |
max |
upper bound |
... |
arguments passed to other methods |
strict |
|
format |
|
Examples
d <- data.frame(
number = c(3,-2,6)
, time = as.Date(c("2018-02-01", "2018-03-01", "2018-04-01"))
, period = c("2020Q1", "2021Q2", "2020Q3")
)
rules <- validator(
in_range(number, min=-2, max=7, strict=TRUE)
, in_range(time, min=as.Date("2017-01-01"), max=as.Date("2018-12-31"))
, in_range(period, min="2020Q1", max="2020Q4")
)
result <- confront(d, rules)
values(result)