powered by
Computes statistical summaries for each level of a factor vector based on associated numeric data.
ft_level_stats(factor_vec, numeric_vec, stat_func)
A data frame with factor levels and their corresponding statistics.
A factor vector.
A numeric vector of the same length as factor_vec.
factor_vec
A function to compute the statistic (e.g., mean, median).
Kai Guo
# 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