title: How to filter cases in a data.table by multiple conditions defined in another data.table
body: <p>I wondered whether there is any efficient way to filter a data.table by multiple conditions defined in another data.table. There are 2 data.table in this case:</p>
  
  <pre><code># the filter data.table defines the condition
  dt_filter&lt;-data.table(A=c(1,2),B=c(8,7))
  # dt1 the data.table to be filtered
  dt1&lt;-data.table(A=rep(c(1,2),5),B=c(8,4,3,1,1,5,9,7,1,1),C=c(rep(1,5),rep(2,5)))
  
  ls_tmp&lt;-lapply (1:nrow(dt_filter),function(i){
  # exclude the record with the A&amp;B defined the filter
  dt1_add&lt;-dt1[A==dt_filter[[i,1]]&amp;B!=dt_filter[[i,2]]]
  })
  result&lt;- rbindlist(ls_tmp)
  </code></pre>
  
  <p>It seems my sample is not efficient because of lapply loop. I am not sure how to re-write it by some other way.</p>