Rename multiple columns given character vectors of column names and replacement [duplicate]

I don’t know if this is the right way to approach it, but

library(dplyr)
df %>% rename_at(vars(col.from), function(x) col.to) %>% head(2)
#               mpg cyl disp bar drat   foo  qsec baz am gear carb
# Mazda RX4      21   6  160 110  3.9 2.620 16.46   0  1    4    4
# Mazda RX4 Wag  21   6  160 110  3.9 2.875 17.02   0  1    4    4

Also note that I live in the future:

# packageVersion("dplyr")
# # [1] ‘0.7.0’

Leave a Comment