title: How to detect consecutive values above a threshold?
body: <p>I have data for which I would like to apply a rolling function to detect at which point a value is greater than a speficic threshold.</p>
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  
  df &lt;- tibble(
    x = 1:10,
    y = c(1, 3, 4, 1, 5, 34, 43, 1, 45, 3)
  )
  
  df
  #&gt; # A tibble: 10 x 2
  #&gt;        x     y
  #&gt;    &lt;int&gt; &lt;dbl&gt;
  #&gt;  1     1     1
  #&gt;  2     2     3
  #&gt;  3     3     4
  #&gt;  4     4     1
  #&gt;  5     5     5
  #&gt;  6     6    34
  #&gt;  7     7    43
  #&gt;  8     8     1
  #&gt;  9     9    45
  #&gt; 10    10     3
  </code></pre>
  
  <p>What I would like is to find the row for which the next 2 values are higher than a certain threshold (say 30). This would produce this:</p>
  
  <pre class="lang-r prettyprint-override"><code>tibble(
    x = 1:10,
    y = c(1, 3, 4, 1, 5, 34, 43, 1, 45, 3),
    i = c(FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE)
  )
  #&gt; # A tibble: 10 x 3
  #&gt;        x     y i    
  #&gt;    &lt;int&gt; &lt;dbl&gt; &lt;lgl&gt;
  #&gt;  1     1     1 FALSE
  #&gt;  2     2     3 FALSE
  #&gt;  3     3     4 FALSE
  #&gt;  4     4     1 FALSE
  #&gt;  5     5     5 FALSE
  #&gt;  6     6    34 TRUE 
  #&gt;  7     7    43 FALSE
  #&gt;  8     8     1 FALSE
  #&gt;  9     9    45 FALSE
  #&gt; 10    10     3 FALSE
  </code></pre>
  
  <p>I have a large dataset (few millions lines) so I am trying to find a efficient solution. Maybe using <code>data.table</code>?
  <sup>Created on 2019-02-26 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.1)</sup></p>