Hi!
The problem in your specific example is that you are using same variable in mutate: x = x-mean(x).
Good way to deal with this specific task is to use mutate_at. Example:
iris %>%
group_by(Species) %>%
mutate_at(c("Sepal.Length", "Sepal.Width"), (function(x) x - mean(x)))
This code will take 2 indicated columns and replace their values with deviations from the mean per group.