lt_eq_gt: Recode variable based on whether it is less than, equal to,...

View source: R/lt_eq_gt.R

lt_eq_gtR Documentation

Recode variable based on whether it is less than, equal to, or greater than a specified comparison value

Description

Recode variable based on whether it is less than, equal to, or greater than a specified comparison value

Usage

lt_eq_gt(x, compare_to, vals = 1:3)

Arguments

x

a numeric vector. The variable to recode.

compare_to

a single numeric value. The comparison value.

vals

a vector of length 3. Defaults to c(1,2,3).

Value

Returns vals[1] if x < compare_to, vals[2] if x == compare_to, and vals[3] if x > compare_to. The function is vectorized so that if length(x) > 1 each x[i] is compared to k and recoded.

Examples

y1 <- 1:10
y2 <- lt_eq_gt(y1, compare_to = 5)


jgabry/RHhelpers documentation built on Feb. 22, 2024, 12:56 p.m.