Below is an example of code I use to normalize by group using dplyr:
mtcars %>% group_by(carb) %>% mutate(norm = (hp - min(hp)) / (max(hp) - min(hp))) %>% ungroup()
I would like to modify this code so that the normalization can be applied to several specific columns at the same time maybe using the function "across" or "purr" or anything else. Can anyone help?
Edited: As you don't want base R.
dplyr
Have a look at
across.