Learn R Programming

fctutils (version 0.0.7)

ft_impute: Impute Missing Values in Factor Vector

Description

Replaces NA values in a factor vector using specified imputation methods.

Usage

ft_impute(factor_vec, method = "mode")

Value

A factor vector with NA values imputed.

Arguments

factor_vec

A factor vector with potential NA values.

method

The imputation method: 'mode', 'random', or a user-defined function.

Author

Kai Guo

Examples

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

# Impute using mode
ft_impute(factor_vec, method = 'mode')

# Impute using random selection
ft_impute(factor_vec, method = 'random')

Run the code above in your browser using DataLab