title: Create conditional variable in multiple data.tables (or data.frames)
body: <p>I want to execute the same action in multiple data.tables (or data.frames). For example, I want to create the same variable conditional on the same rule in all data.tables.</p>
  
  <p>A simple example can be (df1=df2=df3, without loss of generality here)</p>
  
  <pre><code>df1 &lt;- data.frame(var1 = c(1, 2, 2, 2, 1), var2 =c(20, 10, 10, 10, 20), var3 = c(10, 8, 15, 7, 9))
  df2 &lt;- data.frame(var1 = c(1, 2, 2, 2, 1), var2 =c(20, 10, 10, 10, 20), var3 = c(10, 8, 15, 7, 9))
  df3 &lt;- data.frame(var1 = c(1, 2, 2, 2, 1), var2 =c(20, 10, 10, 10, 20), var3 = c(10, 8, 15, 7, 9))
  </code></pre>
  
  <p>My approach was: (i) to create a list of the data frames (list.df), (ii) to loop on this list trying to create the variable:</p>
  
  <p>list.df</p>
  
  <pre><code>list.df&lt;-vector('list',3)
  for(j in 1:3){
    name &lt;- paste('df',j,sep='')
    list.df[j] &lt;- name
  }
  </code></pre>
  
  <p>My (bad) tentative:</p>
  
  <pre><code>for(i in 1:3){
    a&lt;-get(paste(list.df[[i]], "$var1", sep=""))
    b&lt;-get(paste(list.df[[i]], "$var2", sep=""))
    name&lt;-paste(list.df[[i]], "$var.new", sep="")
    assign(name, ifelse(a==2 &amp; b==10, 1, 0))
  }
  </code></pre>
  
  <p>Clearly <code>r</code> cannot create this new variable the way I am doing as I get a error message "object not found".
  Any clues on how to fix my bad code? I have a feeling that <code>dplyr</code> could help me but I don't know how. </p>