title: Loop over list of data frames using data.table
body: <p>I have 3 data frames that I'd like to run the same <code>data.table</code> function on. I could do this manually for each <code>data.frame</code> but I'd like to learn how to do it more efficiently. </p>
  
  <p>Using the <code>data.table</code> package, I want to replace the contents of <code>col1</code> with the contents of <code>col2</code> only if <code>col1</code> contains "a". And I want to run this code over three different dataframes. On a single <code>data.frame</code>, this works fine:</p>
  
  <pre><code>df1 &lt;- data.frame(col1 = c("a", "a", "b"), col2 = c("AA", "AA", "AA"))
  library(data.table)
  dt = data.table(df1)
  dt[grepl(pattern = "a", x = df1$col1),  col1 :=col2]
  </code></pre>
  
  <p>but I am lost trying to get this to run over multiple dataframes:</p>
  
  <pre><code>df1 &lt;- data.frame(col1 = c("a", "a", "b"), col2 = c("AA", "AA", "AA"))
  df2 &lt;- data.frame(col1 = c("b", "b", "a"), col2 = c("AA", "BB", "BB"))
  df3 &lt;- data.frame(col1 = c("b", "b", "b"), col2 = c("AA", "AA", "BB"))
  
  library(data.table)
  listdfs = list(df1, df2, df3)
  for (i in dt[[]]) {
  dt[[i]][grepl(pattern = "a", x = df[[i]]$col1), col1 := col2] }
  </code></pre>
  
  <p>But this obviously doesn't work because I have no clue what I'm doing with the for loop.  Any guidance/teaching would be appreciated. Thanks!</p>