If data frames were not in the list, but simply in the global environment, you can reference them using a vector of string names.
dfs <- c("dfA", "dfB", "dfC") for(df in dfs) { df.tmp <- get(df) names(df.tmp) <- c("A", "B", "C" ) assign(df, df.tmp) }
EDIT
To simplify the code above, you can use
for(df in dfs) assign(df, setNames(get(df), c("A", "B", "C")))
or using data.table , which does not require reassignment.
for(df in c("dfA", "dfB")) data.table::setnames(get(df), c("G", "H"))
Jwilliman
source share