I need to pass a string as a column name using dplyr (code below). I can't get it to work. I've tried using [[name]] and .data[[name]] and this doesn't work. I need a solution specifically that allows me to rename a column as the string I've specified in the variable name.
colnames(mtcars) -> cols
rename_cols <- function(col) {
name = paste0(col, "_new") #I want to be able to parse this into the rename function below
mtcars %>%
rename(
name = col,
)
}
lapply(cols, rename_cols)