fct_recode: Change factor levels by hand

Description Usage Arguments Examples

View source: R/recode.R

Description

Change factor levels by hand

Usage

1

Arguments

.f

A factor (or character vector).

...

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. Levels can be removed by naming them NULL. Uses tidy dots.

Examples

1
2
3
4
5
6
7
8
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")

# If you name the level NULL it will be removed
fct_recode(x, NULL = "apple", fruit = "banana")

tidyverse/forcats documentation built on Jan. 11, 2019, 11:10 a.m.