ft_map_func {fctutils}R Documentation

Map Factor Levels Using a Function

Description

Transforms factor levels by applying a function that can include complex logic.

Usage

ft_map_func(factor_vec, map_func)

Arguments

factor_vec

A factor vector to map.

map_func

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

Value

A factor vector with levels mapped according to the function.

Author(s)

Kai Guo

Examples

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

# Map levels to uppercase if they start with 'a'
ft_map_func(factor_vec, function(x) {
  ifelse(grepl('^a', x), toupper(x), x)
})

[Package fctutils version 0.0.7 Index]