View source: R/fct_recode_if.R
fct_recode_if | R Documentation |
Recode a factor level on a condition
fct_recode_if(f, cond, level)
f |
A factor variable |
cond |
A predicate to determine when the level should be recoded |
level |
The level created based on the condition |
A factor variable with the new level added in
df <- data.frame(x = factor(c("apple", "bear", "banana", "dear")),
y = factor(c("fruit", "animal", "fruit", "animal")))
dplyr::mutate(df, x = fct_recode_if(x, y == "animal", "not a fruit"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.