Can't seem to find any answer to this question. I have no idea what is the best way to do it.
This is a dummy dataframe:
| ID | year | age | death |
|---|---|---|---|
| 1 | 1999 | 18 | 2015 |
| 2 | 1984 | 25 | |
| 3 | 2012 | 24 |
What i want to do is to repeat each row and add 1 to year and age until one of a set of condition is reached
year == 2018 or year == death
Ultimately so the new dataframe looks like this:
| ID | year | age | death |
|---|---|---|---|
| 1 | 1999 | 18 | 2015 |
| 1 | 2000 | 19 | 2015 |
| 1 | 2001 | 20 | 2015 |
| 1 | 2002 | 21 | 2015 |
| 1 | 2003 | 22 | 2015 |
| 1 | 2004 | 23 | 2015 |
| 1 | 2005 | 24 | 2015 |
| 1 | 2006 | 25 | 2015 |
| 1 | 2007 | 26 | 2015 |
| 1 | 2008 | 27 | 2015 |
| 1 | 2009 | 28 | 2015 |
| 1 | 2010 | 29 | 2015 |
| 1 | 2011 | 30 | 2015 |
| 1 | 2012 | 31 | 2015 |
| 1 | 2013 | 32 | 2015 |
| 1 | 2014 | 33 | 2015 |
| 1 | 2015 | 34 | 2015 |
| 2 | 2010 | 25 | |
| 2 | 2011 | 26 | |
| 2 | 2012 | 27 | |
| 2 | 2013 | 28 | |
| 2 | 2014 | 29 | |
| 2 | 2015 | 30 | |
| 2 | 2016 | 31 | |
| 2 | 2017 | 32 | |
| 2 | 2018 | 33 | |
| 3 | 2012 | 24 | |
| 3 | 2013 | 25 | |
| 3 | 2014 | 26 | |
| 3 | 2015 | 27 | |
| 3 | 2016 | 28 | |
| 3 | 2017 | 29 | |
| 3 | 2018 | 30 |
Any suggestions?
Sincerely, A desperate newbie epidemiologist