ft_level_stats: Calculate Statistics for Each Factor Level

View source: R/fct_misc.R

ft_level_statsR Documentation

Calculate Statistics for Each Factor Level

Description

Computes statistical summaries for each level of a factor vector based on associated numeric data.

Usage

ft_level_stats(factor_vec, numeric_vec, stat_func)

Arguments

factor_vec

A factor vector.

numeric_vec

A numeric vector of the same length as factor_vec.

stat_func

A function to compute the statistic (e.g., mean, median).

Value

A data frame with factor levels and their corresponding statistics.

Author(s)

Kai Guo

Examples

# Example data
factor_vec <- factor(c('A', 'B', 'A', 'B', 'C'))
numeric_vec <- c(10, 20, 15, 25, 30)

# Calculate mean for each level
ft_level_stats(factor_vec, numeric_vec, stat_func = mean)

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