title: R repeat rows based on calculation of row elements
body: <p>This is a strange one. I'm trying to do more with vectorized code instead of loops. I know I can do this with loops, what I'm looking for is the vectorized way in R for speed. I have a table creatively named <code>tbl</code> which looks like this:</p>
  
  <pre><code>A ,B ,C  ,D
  1 ,1 ,10 ,22
  2 ,2 ,12 ,32
  3 ,5 ,44 ,37
  </code></pre>
  
  <p>I want to repeat the values of C and D for the number of values between A and B. In this case there would be one instance of the first row, one instance of the second row and 3 repetitions of the third row. The goal is this:</p>
  
  <pre><code>C  ,D
  10 ,22
  12 ,32
  44 ,37
  44 ,37
  44 ,37
  </code></pre>
  
  <p>What I have so far is this but it doesn't work:</p>
  
  <pre><code>rep(list(tbl[,c("C","D")]), (tbl["B"] - tbl["A"] + 1) )
  </code></pre>
  
  <p>It works if I iterate over the rows but I would rather do it in one pass as a vectorized function. I have a feeling the <code>list(tbl[,c("C","D")])</code> is the part that is tripping up because it is not aware of which row it is working on. Any help or guidance is appreciated. If I'm going down the wrong rabbit hole please feel free to let me know. Thanks!</p>