ft_rollup: Aggregate Factor Levels Based on Grouping

View source: R/fct_misc.R

ft_rollupR Documentation

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)

Arguments

factor_vec

A factor vector to aggregate.

groups

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

Value

A factor vector with aggregated levels.

Author(s)

Kai Guo

Examples

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

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