title: Building forvalues loops in R
body: <p>[Working with R 3.2.2]</p>
  
  <p>I have three data frames with the same variables. I need to modify the value of some variables and change the name of the variables (rename the columns). Instead of doing this data frame by data frame, I would like to use a loop. </p>
  
  <p>This is the code I want to run:</p>
  
  <pre><code>#Change the values of the variables
  vlist &lt;- c("var1", "var2", "var3")
  dataframe0[,vlist] &lt;- dataframe0[,vlist]/10
  dataframe1[,vlist] &lt;- dataframe1[,vlist]/10
  dataframe2[,vlist] &lt;- dataframe2[,vlist]/10
  
  #Change the name of the variables
  colnames(dataframe0)[colnames(dataframe0)=="var1"] &lt;- "temp_min"
  colnames(dataframe0)[colnames(dataframe0)=="var2"] &lt;- "temp_max"
  colnames(dataframe0)[colnames(dataframe0)=="var3"] &lt;- "prep"
  
  colnames(dataframe1)[colnames(dataframe1)=="var1"] &lt;- "temp_min"
  colnames(dataframe1)[colnames(dataframe1)=="var2"] &lt;- "temp_max"
  colnames(dataframe1)[colnames(dataframe1)=="var3"] &lt;- "prep"
  
  colnames(dataframe2)[colnames(dataframe2)=="var1"] &lt;- "temp_min"
  colnames(dataframe2)[colnames(dataframe2)=="var2"] &lt;- "temp_max"
  colnames(dataframe2)[colnames(dataframe2)=="var3"] &lt;- "prep"
  </code></pre>
  
  <p>I know the logic to do it with programs like Stata, with a forvalues loop:</p>
  
  <pre><code>#Change the values of the variables
  forvalues i=0/2 {
  dataframe`i'[,vlist] &lt;- dataframe`i'[,vlist]/10
  
  #Change the name of the variables
  colnames(dataframe`i')[colnames(dataframe`i')=="var1"] &lt;- "temp_min"
  colnames(dataframe`i')[colnames(dataframe`i')=="var2"] &lt;- "temp_max"
  colnames(dataframe`i')[colnames(dataframe`i')=="var3"] &lt;- "prep"
  }
  </code></pre>
  
  <p>But, I am not able to reproduce it in R. How should I proceed? Thanks in advance!</p>