ft_remove_levels {fctutils}R Documentation

Remove Specified Levels from a Factor

Description

Removes specified levels from a factor vector, keeping the remaining levels and their order unchanged.

Usage

ft_remove_levels(factor_vec, levels_to_remove, remove_na = TRUE)

Arguments

factor_vec

A factor vector from which levels will be removed.

levels_to_remove

A character vector of levels to be removed from the factor.

remove_na

remove NA from the output? Default is TRUE.

Value

A factor vector with specified levels removed and remaining levels unchanged.

Author(s)

Kai Guo

Examples

# Example factor vector
factor_vec <- factor(c('apple', 'banana', 'cherry', 'date', 'fig', 'grape'))

# Remove levels 'banana' and 'date'
ft_remove_levels(factor_vec, levels_to_remove = c('banana', 'date'))

[Package fctutils version 0.0.7 Index]