title: Faster equivalent to group_by %>% expand in R
body: <p>I am trying to create a sequence of years for multiple IDs in R. My input table has a single row for each ID, and gives a Start_year. It looks like this:</p>
  
  <pre><code>ID    Start_year
  01          1999
  02          2004
  03          2015
  04          2007
  </code></pre>
  
  <p>etc...</p>
  
  <p>I need to create a table with multiple rows for each ID, showing each year from their Start_year up to 2015. I will then use this to join to another table. So in my example, ID1 would have 17 rows with the years 1999:2015. ID2 would have 12 rows 2004:2015, ID3 would have 1 row 2015, and ID4 would have 9 rows 2007:2015.</p>
  
  <p>For a subset of my data I can get this to work using the following code:</p>
  
  <pre><code>df %&gt;% group_by(ID) %&gt;% expand(year = Start_year:2015, Start_year) %&gt;% select(-Start_year)
  </code></pre>
  
  <p>However, my full dataset has about 5 million IDs, and this command seems to be extremely slow, taking many hours.</p>
  
  <p>I'm therefore looking for a faster implementation of this command in R. In my experience, data.table commands often seem to be faster than dplyr/tidyr - however, I am quite unfamiliar with data.table syntax.</p>