I want to calculate the difference each row has from its group's mean. Is there a way to do this without creating an intermediate table and joining it?
group_summary <- mtcars %>%
group_by(cyl) %>%
summarize(mean_mpg = mean(mpg))
left_join(mtcars, group_summary) %>%
mutate(mpg_diff_from_group = mpg - mean_mpg)