ft_map_func | R Documentation |
Transforms factor levels by applying a function that can include complex logic.
ft_map_func(factor_vec, map_func)
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. |
A factor vector with levels mapped according to the function.
Kai Guo
# 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)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.