ft_group_by_prefix: Group Factor Levels by Common Prefix

View source: R/single_fct.R

ft_group_by_prefixR 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)

fctutils documentation built on Oct. 1, 2024, 1:07 a.m.