forcats (version 0.1.1)

fct_relevel: Change the order of levels in a factor

Description

This is a generalisaton of relevel that allows you to move any number of levels to the front.

Usage

fct_relevel(f, ...)

Arguments

f
A factor.
...
Character vector of levels. Any levels not mentioned will be left in existing order, after the explicitly mentioned levels.

Examples

Run this code
f <- factor(c("a", "b", "c"))
fct_relevel(f)
fct_relevel(f, "c")
fct_relevel(f, "b", "a")

# You'll get a warning if the levels don't exist
fct_relevel(f, "d")

Run the code above in your browser using DataCamp Workspace