Statistics by group
stats_by_group.RdThis function computes a summary statistic by group for a given vector of data.
Examples
# Generate some fictional data
set.seed(100)
data_vector <- rnorm(100)
group_vector <- as.factor(sample(c("A", "B", "C"), size = 100, replace = TRUE))
# Compute the mean of data_vector for each group in group_vector
stats_by_group(data_vector, group_vector, stat = mean)
#> A B C
#> -0.12992515 0.07199512 0.02461430