Learn R Programming

fctutils (version 0.0.7)

ft_level_stats: 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)

Value

A data frame with factor levels and their corresponding statistics.

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

Author

Kai Guo

Examples

Run this code
# 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)

Run the code above in your browser using DataLab