it is possible to subtract certain rows and rename them?
year <- c(2005,2005,2005,2006,2006,2006,2007,2007,2007)
category <- c("a","b","c","a","b","c", "a", "b", "c")
value <- c(2,2,10,3,3,12,4,4,16)
df <- data.frame(year, category,value, stringsAsFactors = FALSE)
And this is how the result should look:
| year | category | value |
|---|---|---|
| 2005 | a | 2 |
| 2005 | b | 2 |
| 2005 | c | 4 |
| 2006 | a | 3 |
| 2006 | b | 3 |
| 2006 | c | 12 |
| 2007 | a | 4 |
| 2007 | b | 4 |
| 2007 | c | 16 |
| 2005 | c-b | 2 |
| 2006 | c-b | 9 |
| 2007 | c-b | 12 |