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