Learn R Programming

fctutils (version 0.0.7)

ft_apply: Apply a Function to Factor Levels

Description

Transforms factor levels by applying a function to each level.

Usage

ft_apply(factor_vec, apply_func)

Value

A factor vector with transformed levels.

Arguments

factor_vec

A factor vector to transform.

apply_func

A function to apply to each level.

Author

Kai Guo

Examples

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

# Append '_fruit' to each level
ft_apply(factor_vec, function(x) paste0(x, '_fruit'))

Run the code above in your browser using DataLab