title: Replicating rows in data.table by column value
body: <p>I have a dataset that is structured as following:</p>
  
  <p><code>data &lt;- data.table(ID=1:10,Tenure=c(2,3,4,2,1,1,3,4,5,2),Var=rnorm(10))</code></p>
  
  <pre><code>    ID Tenure         Var
   1:  1      2 -0.72892371
   2:  2      3 -1.73534591
   3:  3      4  0.47007030
   4:  4      2  1.33173044
   5:  5      1 -0.07900914
   6:  6      1  0.63493316
   7:  7      3 -0.62710577
   8:  8      4 -1.69238758
   9:  9      5 -0.85709328
  10: 10      2  0.10716830
  </code></pre>
  
  <p>I need to replicate each row N=<code>Tenure</code> times. e.g. I need to replicate the first row 2 times (since <code>Tenure = 2</code>.</p>
  
  <p>I need my transformed dataset to look like the following:</p>
  
  <pre><code>setkey(data,ID)
  print(data[,.(ID=rep(ID,Tenure))][data][, Indx := 1:.N, by=ID])
  
     ID Tenure        Var Indx
  1:  1      2 -0.7289237    1
  2:  1      2 -0.7289237    2
  3:  2      3 -1.7353459    1
  4:  2      3 -1.7353459    2
  5:  2      3 -1.7353459    3
  6:  3      4  0.4700703    1
  ...
  ...
  </code></pre>
  
  <p>Is there a more efficient way (a more <code>data.table</code> way) to do this? My way is pretty slow. I was thinking there should be a way to do this using a <code>by-without-by</code> merge usng <code>.EACHI</code>?</p>