Learn R Programming

forcats (version 0.0.0.9000)

fct_recode: Change the levels of a factor

Description

Change the levels of a factor

Usage

fct_recode(f, ...)

Arguments

f
A factor.
...
A sequence of named character vectors where the name gives the new level, and the value gives the old level. Levels not otherwise mentioned will be left as is.

Examples

Run this code
x <- factor(c("apple", "bear", "banana", "dear"))
fct_recode(x, fruit = "apple", fruit = "banana")

# If you make a mistake you'll get a warning
fct_recode(x, fruit = "apple", fruit = "bananana")

Run the code above in your browser using DataLab