This is an extension of Subtract previous year's from value from each grouped row in data frame. The option using plyr makes complete sense.
Now, I'm trying to add a couple more columns. I've also modified year so it's an actual year with different starting points by id. Here is a link to tab-delimited df: https://dl.dropbox.com/u/9699533/df.txt
I am unable to get a pointer to the previous row when I'm in the current row. I'd like to pass this to the function part of plyr::transform. How do I write this, please? Thanks!
~~~~ Alternate dataframe input ~~~~~
> dput(df)
structure(list(id = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L,
4L, 4L, 5L, 5L, 5L), value = c(6L, 16L, 21L, 5L, 10L, 26L, 2L,
12L, 26L, 9L, 16L, 26L, 2L, 15L, 29L), year = c(2007L, 2008L,
2009L, 2011L, 2012L, 2013L, 2004L, 2004L, 2006L, 2010L, 2011L,
2012L, 2014L, 2015L, 2016L), actual = c(6L, 10L, 5L, 5L, 5L,
16L, 2L, 10L, 14L, 9L, 7L, 10L, 2L, 13L, 14L)), .Names = c("id",
"value", "year", "actual"), class = "data.frame", row.names = c(NA,
-15L))