ft_remove_levels: Remove Specified Levels from a Factor

View source: R/single_filter.R

ft_remove_levelsR 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'))

fctutils documentation built on Oct. 1, 2024, 1:07 a.m.