Learn R Programming

fctutils (version 0.0.7)

ft_filter_func: 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)

Value

A factor vector with levels filtered according to the function.

Arguments

factor_vec

A factor vector to filter.

func

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

Author

Kai Guo

Examples

Run this code
# 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))

Run the code above in your browser using DataLab