I\'m trying to add a common prefix to each of the variable names in a data.frame. For example, using the mtcars data, I could add the prefix \"cars.\" using th
mtcars
The latest solution (2020) seems to use rename_with, which is available in dplyr 1.0.0 and higher:
dplyr
mtcars %>% rename_with(.fn = ~ paste0("Myprefix_", .x, "_Mypostfix")) -> mtcars.custom
Use the .cols = argument to specify a subset of variables, it defaults to everything().
.cols =
everything()