title: Find consecutive sequence of zeros in R
body: <p>I have a data.frame really big (actually a data.table). Now, to simplify things, let's assume my data.frame is just as follow:</p>
  
  <pre><code>x &lt;- c(1, 1, 0, 0, 1, 0, 0, NA, NA, 0) 
  y &lt;- c(1 ,0 ,NA, NA, 0, 0, 0, 1, 1, 0)
  mydf &lt;- data.frame(rbind(x,y))
  </code></pre>
  
  <p>I'd like to identify in which row (if any) the last sequence is formed by three consecutive zeros, not considering NAs. So, in the example above, the first row has three consecutive zeros in the last sequence, but not the second one.</p>
  
  <p>I know how to do that if only I have a vector (not a data.frame):</p>
  
  <pre><code>runs &lt;-  rle(x[is.na(x)==F])
  
  runs$lengths[length(runs$lengths)] &gt; 2 &amp; runs$values[length(runs$lengths)]==0
  </code></pre>
  
  <p>I obviously can do a loop and I'll have what I want. But it'll be incredibly inefficient and my actual data.frame is quite big. So, any ideas on how to do in a fastest way?</p>
  
  <p>I guess apply can be useful, but I'm not able to thinking of using it right now. Also, maybe there is a data.table way of doing this?</p>
  
  <p>ps.: Actually, this data.frame is a reshaped version of my original data.table.  If somehow I can do the job with the data.frame in the original format, it's ok. To see how is my data.frame originally, just think of it as:</p>
  
  <pre><code>x &lt;- c(1, 1, 0, 0, 1, 0, 0, 0) 
  y &lt;- c(1 ,0 , 0, 0, 0, 1, 1, 0)
  
  myOriginalDf &lt;- data.frame(value=c(x,y), id=rep(c('x','y'), c(length(x), length(y))))
  </code></pre>