title: Remove rows after a certain date based on a condition in R
body: <p>There are similar questions I've seen, but none of them apply it to specific rows of a data.table or data.frame, rather they apply it to the whole matrix.<br>
  <a href="https://stackoverflow.com/questions/23622338/subset-a-dataframe-between-2-dates-in-r-better-way">Subset a dataframe between 2 dates</a><br>
  <a href="https://stackoverflow.com/questions/25024510/how-to-select-some-rows-with-specific-date-from-a-data-frame-in-r">How to select some rows with specific date from a data frame in R</a>  </p>
  
  <p>I have a dataset with patients who were diagnosed with OA and those who were not:  </p>
  
  <pre><code> dt &lt;- data.table(ID = seq(1,10,1), OA = c(1,0,0,1,0,0,0,1,1,0), 
               oa.date = as.Date(c("01/01/2006", "01/01/2001", "01/01/2001", "02/03/2005","01/01/2001","01/01/2001","01/01/2001","05/06/2010", "01/01/2011", "01/01/2001"), "%d/%m/%Y"),
               stop.date = as.Date(c("01/01/2006", "31/12/2007", "31/12/2008", "02/03/2005", "31/12/2011", "31/12/2011", "31/12/2011", "05/06/2010", "01/01/2011", "31/12/2011"), "%d/%m/%Y"))
  dt$oa.date[dt$OA==0] &lt;- NA
  
  &gt; dt
      ID OA    oa.date  stop.date
   1:  1  1 2006-01-01 2006-01-01
   2:  2  0       &lt;NA&gt; 2007-12-31
   3:  3  0       &lt;NA&gt; 2008-12-31
   4:  4  1 2005-03-02 2005-03-02
   5:  5  0       &lt;NA&gt; 2011-12-31
   6:  6  0       &lt;NA&gt; 2011-12-31
   7:  7  0       &lt;NA&gt; 2011-12-31
   8:  8  1 2010-06-05 2010-06-05
   9:  9  1 2011-01-01 2011-01-01
  10: 10  0       &lt;NA&gt; 2011-12-31
  </code></pre>
  
  <p>What I want to do is delete those who were diagnosed with OA (<code>OA==1</code>) before <code>start</code>:  </p>
  
  <pre><code>start &lt;- as.Date("01/01/2009", "%d/%m/%Y")
  </code></pre>
  
  <p>So I want my final data to be:</p>
  
  <pre><code>&gt; dt
       ID OA    oa.date  stop.date
   1:  2  0       &lt;NA&gt; 2009-12-31
   2:  3  0       &lt;NA&gt; 2008-12-31
   3:  5  0       &lt;NA&gt; 2011-12-31
   4:  6  0       &lt;NA&gt; 2011-12-31
   5:  7  0       &lt;NA&gt; 2011-12-31
   6:  8  1 2010-06-05 2010-06-05
   7:  9  1 2011-01-01 2011-01-01
   8: 10  0       &lt;NA&gt; 2011-12-31
  </code></pre>
  
  <p>My  tries are: </p>
  
  <pre><code>  dt[dt$OA==1] &lt;- dt[!(oa.date &lt; start)]  
  </code></pre>
  
  <p>I've also tried a loop but to no effect.</p>
  
  <p>Any help is much appreciated.</p>