rng2lev: Convert sortable values in levels by range

View source: R/rng2lev.R

rng2levR Documentation

Convert sortable values in levels by range

Description

Convert values of x to the N levels in levs distinguished by the N-1 thresholds in cuts.

When values of x are equal to a value of cuts, assignment to level is dependent on whether the value of each element of cuts is less than 0 vs. greater than or equal to 0.

For a value in cuts less than 0, the level assigned is the lower of the levels distinguished by that value of cuts.

Otherwise, the level assigned is the upper of the levels distinguished by that value of cuts.

Usage

rng2lev(x, cuts, levs)

Arguments

x

An atomic object of sortable values.

cuts

An atomic vec of N-1 cuts for N levels.

levs

An atomic vec of N level labels.

Value

An atomic object of the same dimension as x and the same mode as levs.

See Also

Other conversions: hex_dec_help(), tocase(), u2u_help()

Examples

numVALS <- -5:5
chrVALS <- letters[1:11]
ordVALS <- factor(chrVALS, levels = chrVALS, ordered = TRUE)
numCUTS <- c(-3, 0, 3)
chrCUTS <- c("c", "f", "i")
ordCUTS <- factor(chrVALS, levels = chrVALS, ordered = TRUE)
rngLEVS <- c("A", "B", "C", "D")
rng2lev(numVALS, numCUTS, rngLEVS)
rng2lev(chrVALS, chrCUTS, rngLEVS)
rng2lev(ordVALS, ordCUTS, rngLEVS)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.