ft_filter_func: Filter Factor Levels Using a Function

View source: R/fct_misc.R

ft_filter_funcR Documentation

Filter Factor Levels Using a Function

Description

Removes levels from a factor vector based on a user-defined function.

Usage

ft_filter_func(factor_vec, func)

Arguments

factor_vec

A factor vector to filter.

func

A function that takes a character vector of levels and returns a logical vector.

Value

A factor vector with levels filtered according to the function.

Author(s)

Kai Guo

Examples

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

# Remove levels that start with 'b'
ft_filter_func(factor_vec, function(x) !grepl('^b', x))

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