title: Is there a function in dplyr corresponding to the function `shift` in data.table?
body: <p>In the <code>data.table</code> package, there is a <code>shift</code> function which helps process data in consecutive rows. Like this:</p>
  
  <pre><code>&gt; shift(1:10, 1:3, type = "lag")
  [[1]]
   [1] NA  1  2  3  4  5  6  7  8  9
  
  [[2]]
   [1] NA NA  1  2  3  4  5  6  7  8
  
  [[3]]
   [1] NA NA NA  1  2  3  4  5  6  7
  </code></pre>
  
  <p>And I know that in <code>dplyr</code> package, there are functions like <code>lead</code> and <code>lag</code> which do about the same thing as <code>shift</code> in the <code>data.table</code> package. But the problem is that you can not really specify consecutive rows but only check two rows at the same time. For example:</p>
  
  <pre><code>&gt; lag(1:10, 1)
   [1] NA  1  2  3  4  5  6  7  8  9
  &gt; lag(1:10, 2)
   [1] NA NA  1  2  3  4  5  6  7  8
  &gt; lag(1:10, 3)
   [1] NA NA NA  1  2  3  4  5  6  7
  </code></pre>
  
  <p>But you cannot do something like <code>lag(1:10, 1:3)</code> which gives errors as </p>
  
  <pre><code>lag(1:10, 1:3)
  </code></pre>
  
  <blockquote>
    <p>Error in lag(1:10, 1:3) : n must be a single positive integer
    In addition: Warning message:
    In if (n == 0) return(x) :
      the condition has length > 1 and only the first element will be used</p>
  </blockquote>
  
  <p>So my question is that if there is a function in <code>dplyr</code> that corresponds to the function <code>shift</code> in <code>data.table</code>. Any clarification will be appreciated!</p>