Is it possible to pass variables to
rename? For instance:
fake1 <- rename(mtcars, replace=c("mpg"="new.mpg"))
works just fine. However,
old_name <- "mpg"
fake2 <- rename(mtcars, replace=c(old_name="new.mpg"))
fails to map
"mpg", instead gives the warning
values were not present inx
Obviously I can rename using something like
names(mtcars)[names(mtcars)==old_name] <- "new.mpg"
rename is so convenient (also I don't quite understand why the variable wouldn't be interpreted as the string it represents).
Try this instead:
rename(mtcars,replace = setNames("new.mpg",old_name))