Learn R Programming

fctutils (version 0.0.7)

ft_replace_na: Replace NA Values in Factor Vector

Description

Replaces NA values in a factor vector with a specified level.

Usage

ft_replace_na(factor_vec, replacement_level)

Value

A factor vector with NA values replaced.

Arguments

factor_vec

A factor vector.

replacement_level

A string specifying the level to replace NA values with.

Author

Kai Guo

Examples

Run this code
# Example factor vector
factor_vec <- factor(c('apple', NA, 'banana', 'cherry', NA))

# Replace NAs with 'Unknown'
ft_replace_na(factor_vec, replacement_level = 'Unknown')

Run the code above in your browser using DataLab