fct_recode | R Documentation |
Change factor levels by hand
fct_recode(.f, ...)
.f |
A factor (or character vector). |
... |
< |
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") # Wrap the left hand side in quotes if it contains special variables fct_recode(x, "an apple" = "apple", "a bear" = "bear") # When passing a named vector to rename levels use !!! to splice x <- factor(c("apple", "bear", "banana", "dear")) levels <- c(fruit = "apple", fruit = "banana") fct_recode(x, !!!levels)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.