title: Looping through list of data frames in R
body: <p>I have a series of data frames, <code>df1</code> <code>df2</code>, where each data frame follow this structure: </p>
  
  <pre><code>x &lt;- c(1:5)
  y &lt;- c(1:5)
  df1 &lt;- data.frame("Row One"=x, "Row Two"=y)
  </code></pre>
  
  <p>Sample output for df1:</p>
  
  <pre><code> Row.One    Row.Two
      1           1
      2           2
      3           3
      4           4
      5           5
  </code></pre>
  
  <p>I put each data frame into a list <code>dfList &lt;- list(df1,df2...)</code></p>
  
  <p>Now I want to loop through each data frame object in this list to replace the column names using this command:</p>
  
  <pre><code>a &lt;- grep("One", colnames(df))
  b &lt;- grep("Two", colnames(df))
  
  names(df)[a] &lt;- "R1"
  names(df)[b] &lt;- "R2"
  </code></pre>
  
  <p>How can I structure a loop in R so that I no matter how many data frames are in the list object the column name changing commands above will be applied to each data frame? </p>