Does anybody know how to sum rows of selected columns under a particular condition?
For instance, I have five columns whose rows are sorted by year from 2000 to 2008. I need to sum only those rows that are in "year<2006" and add a new total column (with NA's since other years weren't involved).
I suppose group_by won't work because I do not need to sum by group
My data is
A <- c(1,2,3,4,5,6,7,8,9,10)
B <- c(1,2,3,4,5,6,7,8,9,10)
Year <- c(2000, 2001, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008)
dta <- as.data.frame(A,B, Year)
I would love to obtain something like
TotalColumn Year
2 2000
4 2001
6 2000
8 2001
10 2003
12 2004
14 2005
NA 2006
NA 2007
NA 2008