I'm using rename
from the dplyr
library in R to rename column names. I tried to use a loop to achieve this, which runs without error. However, no column names are updated. The loop is:
for (i in 1:length(columns)) {
newcol <- columns[i]
oldcol <- names(census)[i]
rename(census, newcol = oldcol)
}
The 'columns' variable is a vector containing the new column names (of the same length as the old column names), and 'census' is the tibble containing the data with old column names. When just printing 'newcol' and 'oldcol' for each loop iteration, the names are correct - they just don't seem to then be renamed using the 'rename' line.