In a loop, I am trying to perform a simple renaming of the variables in a df.
Without the loop, this works perfectly:
names(c1) <- c("sales", "month")
With a loop-friendly approach ("1" in place of i in the dry-run example) the following correctly references names(c1):
names(get(paste("c","1", sep="")))
but as I write the whole operation I get an error to the tune of "only the first element is used as variable name", here's the code:
assign(names(get(paste("c","1", sep=""))), c("sales", "month"))
I don't know what the error means, but no column title has been changed.
Any ideas?
Thanks,
Roberto