fct_recode_if: Recode a factor level on a condition

View source: R/fct_recode_if.R

fct_recode_ifR Documentation

Recode a factor level on a condition

Description

Recode a factor level on a condition

Usage

fct_recode_if(f, cond, level)

Arguments

f

A factor variable

cond

A predicate to determine when the level should be recoded

level

The level created based on the condition

Value

A factor variable with the new level added in

Examples

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"))

philstraforelli/forcatsmisc documentation built on July 4, 2023, 9:52 a.m.