Learn R Programming

fctutils (version 0.0.7)

ft_rollup: Aggregate Factor Levels Based on Grouping

Description

Aggregates the levels of a factor vector based on another grouping vector.

Usage

ft_rollup(factor_vec, groups)

Value

A factor vector with aggregated levels.

Arguments

factor_vec

A factor vector to aggregate.

groups

A vector of the same length as factor_vec indicating group assignments.

Author

Kai Guo

Examples

Run this code
# Example factor vector and groups
factor_vec <- factor(c('apple', 'banana', 'cherry', 'date', 'fig'))
groups <- c('fruit', 'fruit', 'fruit', 'dry fruit', 'dry fruit')

# Aggregate levels based on groups
ft_rollup(factor_vec, groups)

Run the code above in your browser using DataLab