title: How to filter data.table conditionally in R
body: <p>I am doing operations in two columns of a data.table in R. I have first filtered the datatable by DATE, by1min and by EX, but then I realized that I actually don't want the data within the 1 minute bin. I want it for everything before that bin.</p>
  
  <p>What I had before was:</p>
  
  <pre><code>bid_ask &lt;- new_file[,list(btail=tail(BID,n=1),atail=tail(ASK,n=1)), by=c("DATE","by1min","EX")]
  </code></pre>
  
  <p>And now I wanted to do something like:</p>
  
  <pre><code>bid_ask &lt;- new_file[,list(btail=tail(BID,n=1),atail=tail(ASK,n=1)), by=c("DATE",TIME_M[TIME_M&lt;by1min],"EX")]
  </code></pre>
  
  <p>But this does not seem to be the structure for data.table. </p>
  
  <p>Does anyone know how to filter conditionally within "by"?</p>
  
  <p>My data looks like this:</p>
  
  <pre><code>         DATE   TIME_M EX SYM_SUFFIX   BID   ASK by1min
  1: 2016-03-01 14400.02  P         NA 60.00 95.00  14400
  2: 2016-03-01 24889.07  T         NA 60.01 65.00  24840
  3: 2016-03-01 24889.25  T         NA 60.01 64.99  24840
  4: 2016-03-01 25085.24  T         NA 60.01 64.99  25080
  5: 2016-03-01 25085.36  T         NA 62.50 64.99  25080
  6: 2016-03-01 25103.37  T         NA 62.51 64.99  25080
  </code></pre>