fct_explicit_na_if: Insertion of explicit missing values in a factor

View source: R/utils_factor.R

fct_explicit_na_ifR Documentation

Insertion of explicit missing values in a factor

Description

[Stable]

This inserts explicit missing values in a factor based on a condition. Additionally, existing NA values will be explicitly converted to given na_level.

Usage

fct_explicit_na_if(x, condition, na_level = "<Missing>")

Arguments

x

(factor)
the original factor.

condition

(logical)
positions at which to insert missing values.

na_level

(string)
which level to use for missing values.

Value

A modified factor with inserted and existing NA converted to na_level.

See Also

forcats::fct_na_value_to_level() which is used internally.

Examples

fct_explicit_na_if(factor(c("a", "b", NA)), c(TRUE, FALSE, FALSE))


tern documentation built on Sept. 24, 2024, 9:06 a.m.