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
Another dplyr solution:
dplyr
I find it easiest with the dplyr rename_all, rename_at, rename_if
rename_all
rename_at
rename_if
Try this for renaming all column names:
mtcars %>% rename_all(function(x){paste0("cars.", x)})
Try this for renaming "some" column names:
mtcars %>% rename_at(vars(hp:wt) ,function(x){paste0("cars.", x)})