title: find index based on condition in data.table
body: <p>I have data like this:</p>
  <pre><code>library(data.table)
  
  dt1 &lt;- data.table(
    id = 1,
    week = c( seq(1:260))
  )
  dt1[0:100, status := &quot;A&quot;][101:260, status := &quot;B&quot;]
  
  dt2 &lt;- data.table(
    id = 2,
    week = c( seq(1:260))
  )
  dt2[0:34, status := &quot;A&quot;][35:70, status := &quot;B&quot;][71:260, status := &quot;A&quot;]
  
  dt3 &lt;- data.table(
    id = 3,
    week = c( seq(1:260))
  )
  dt3[0:80, status := &quot;A&quot;][81:90, status := &quot;B&quot;][91:100, status := &quot;A&quot;][101:260, status := &quot;B&quot;]
  
  data &lt;- rbind(dt1,dt2,dt3)
  </code></pre>
  <p>I would like to find, for each unique id, the index before which a 52 week period has passed with at least 75% (39 weeks) with status==&quot;B&quot;. I would want the following end product:</p>
  <pre><code>data_want &lt;- data.table(
    id = c(1,3),
    week = c(153, 133)
  )
  
  </code></pre>
  <p>For id 1, 52 weeks after 101 (the first row with status==B) is 153 and at least 75% of that period, status==B. And so on.</p>
  <p>Any suggestions?</p>