I'm trying to rename several variables by attaching a string from a loop:
df <- data.frame(net_low_mptc=1:3, net_medium_mptc=4:6, net_high_mptc=7:9)
x<-c("low","medium","high")
for(lvl in x) {
rename(df, c(sprintf("net_%s_mptc", lvl) = sprintf("bill_%s_F", lvl))) }
The error is caused by the sprintf expression:
Error: unexpected '=' in:
"for(lvl in x) {
rename(df, c(sprintf("net_%s_mptc", lvl) ="