ft_group_by_prefix {fctutils} | R Documentation |
Group Factor Levels by Common Prefix
Description
Groups factor levels by a common prefix of specified length.
Usage
ft_group_by_prefix(factor_vec, prefix_length)
Arguments
factor_vec |
A factor vector to be grouped. |
prefix_length |
An integer specifying the number of characters in the prefix. |
Value
A factor vector with levels grouped by the common prefix.
Author(s)
Kai Guo
Examples
# Example factor vector
factor_vec <- factor(c('apple_red', 'apple_green', 'banana_yellow', 'banana_green', 'cherry_red'))
# Group by first 5 characters (common prefix)
ft_group_by_prefix(factor_vec, prefix_length = 5)
[Package fctutils version 0.0.7 Index]