Learn R Programming

fctutils (version 0.0.7)

ft_split_levels: Split Factor Levels into Multiple Factors

Description

Splits the levels of a factor vector into multiple factors based on a specified delimiter.

Usage

ft_split_levels(factor_vec, delimiter, names = NULL)

Value

A data frame containing the resulting factors.

Arguments

factor_vec

A factor vector to split.

delimiter

A character string used to split the factor levels.

names

A character vector specifying names for the resulting factors. Default is NULL, in which case factors are named 'Factor1', 'Factor2', etc.

Author

Kai Guo

Examples

Run this code
# Example factor vector
factor_vec <- factor(c('red_large', 'blue_small', 'green_medium'))

# Split levels into two factors
ft_split_levels(factor_vec, delimiter = '_')

Run the code above in your browser using DataLab