I have a cohort life expectancy data, which I would like to repeat the last row n times, but changing some values. I want to find a general function that can be applied to all sizes of data frames.
> df <- data.frame(Year = c(2000,2001,2002), Age = c(0,1,2), x = c(1,2,3), y = c(0.3,0.7,0.5))
> df
Year Age x y
1 2000 0 1 0.3
2 2001 1 2 0.7
3 2002 2 3 0.5
I want to repeat the last row, say 3 times, while increasing the value of Year and Age by 1 for every new row that I create, like this:
> df2
Year Age x y
1 2000 0 1 0.3
2 2001 1 2 0.7
3 2002 2 3 0.5
4 2003 3 3 0.5
5 2004 4 3 0.5
6 2005 5 3 0.5
Basically increasing the value of Year and Age but letting x and y stay constant.