title: Creating a sequence in a data.table depending on a column
body: <p>Say I have the following data.table:</p>
  
  <pre><code>library(data.table)
  
  DT &lt;- data.table(R=sample(0:1, 10000, rep=TRUE), Seq=0)
  </code></pre>
  
  <p>Which returns something like:</p>
  
  <pre><code>       R Seq
      1: 1   0
      2: 1   0
      3: 0   0
      4: 0   0
      5: 1   0
     ---      
   9996: 1   0
   9997: 0   0
   9998: 0   0
   9999: 0   0
  10000: 1   0
  </code></pre>
  
  <p>I want to generate a sequence (1, 2, 3,..., n) that resets whenever R changes from the previous row.  Think of it like I'm counting a streak of random numbers.</p>
  
  <p>So the above would then look like:</p>
  
  <pre><code>       R Seq
      1: 1   1
      2: 1   2
      3: 0   1
      4: 0   2
      5: 1   1
     ---      
   9996: 1   5
   9997: 0   1
   9998: 0   2
   9999: 0   3
  10000: 1   2
  </code></pre>
  
  <p>Thoughts?</p>