Skip to contents

Calculate the value of x based on the cut points and corresponding segment values

Usage

cut_value(x, breaks, values, right = TRUE, if_na = NA)

Arguments

x

A numeric value.

breaks

A numeric vector indicating the cut points, left open and right closed.

values

A vector indicating the return values of each segment, its length must be equal to breaks + 1.

right

Logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.

if_na

A value of the same type as values used to determine the value returned when x is NA.

Value

A value from values.

Examples

cut_value(2, 1, c(1, -1))
#> [1] -1
cut_value(2, 1, LETTERS[1:2])
#> [1] "B"
cut_value(2, c(1, 3), c(1, 3, 5))
#> [1] 3