Learn R Programming

sjmisc (version 1.8)

ref_lvl: Change reference level of (numeric) factors

Description

Changes the reference level of numeric factor. See 'Details'.

Usage

ref_lvl(x, value = NULL)
ref_lvl(x) <- value

Arguments

x
factor with numeric levels where a new reference level should be set.
value
Numeric, the new reference level.

Value

x with new reference level. See 'Details'.

Details

Unlike relevel, this function a) only accepts numeric factors and b) changes the reference level by recoding the factor's values using the rec function. Hence, all values from lowest up to the reference level indicated by value are recoded, with value starting as lowest factor value. See 'Examples'.

See Also

to_factor to convert numeric vectors into factors; rec to recode variables.

Examples

Run this code
data(efc)
x <- to_factor(efc$e42dep)
str(x)
table(x)

ref_lvl(x) <- 3
str(x)
table(x)

Run the code above in your browser using DataLab