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
Indeed, you can use rename_ (NSE rename itself doesn’t work):
rename_
rename
data %>% rename_(.dots = setNames(names(.), paste0('cars.', names(.))))
… but honestly, why? Just assigning names directly is shorter and more readable:
data %>% setNames(paste0('cars.', names(.)))