Learn R Programming

fctutils (version 0.0.7)

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

Value

A factor vector with levels grouped by the common prefix.

Arguments

factor_vec

A factor vector to be grouped.

prefix_length

An integer specifying the number of characters in the prefix.

Author

Kai Guo

Examples

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

Run the code above in your browser using DataLab