Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

frelevel

Modified relevel() function


Description

The base function relevel() accepts a single argument "ref", which can only be a scalar and not a vector of values. frelevel() accepts more (even all) levels and reorders them.

Usage

frelevel(variable, levels)

Arguments

variable

The categorical variable of interest

levels

One or more levels of the factor, in the desired order

Value

A factor of the same length as the initial one.

Author(s)

Adrian Dusa

See Also

Examples

words <- c("ini", "mini", "miny", "moe")
variable <- factor(words, levels = words)

# modify the order of the levels, keeping the order of the values
frelevel(variable, c("moe", "ini", "miny", "mini"))

admisc

Adrian Dusa's Miscellaneous

v0.12
GPL (>= 3)
Authors
Adrian Dusa [aut, cre, cph] (<https://orcid.org/0000-0002-3525-9253>)
Initial release
2021-03-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.