In a tidy data frame with multiple observations/values for levels of categorical variables, is it possible to ADD a summary statistic value (e.g. mean) as a new column/variable to the data frame? Such that this mean would be repeated for multiple rows where it is describing that grouping of factors.

I successfully calculated the summary statistics using this code and creating a new data frame. This new data frame then has fewer observations because it is combining the observations of the input tidy_data dataframe. However, I would like to add the mean values as a new column to the original tidy_data dataframe rather than creating a separate summary data frame such that each original observation is tied to its grouped mean value as well as its raw value.

sum_stats <- tidy_data %>%

group_by(factor1, factor2, factor3) %>%

# group by categorical variables

summarize(

population_mean = mean(freq), # calc mean

population_sd = sd(freq), # calc standard dev

)

Thanks in advance for any input and help!