I have the below data table in R:
n s b y
1 a 1Q 1990 Rank1 10
2 a 2Q 1990 Rank1 43
3 b 1Q 1991 Rank2 42
4 b 3Q 2000 Rank3 66
5 a 4Q 1991 Rank1 55
6 c 1Q 2005 rank3 44
I want to sum up the y column based on the values of the rest columns. For example, in column n value "a", in column s value "Rank1". The caveat is that i want to sum all the numbers for each quarter after the initial one and not the others before it for example. for 1Q 1990 i want to add all other numbers for the quarters after 1Q 1990 up to 1Q 2005, for 2Q 1990 i want to add all numbers up to 1Q 2005 but not 1Q 1990.
So the final outcome should be something like this:
n s b y
1 a 1Q 1990 Rank1 108
2 a 2Q 1990 Rank1 98
3 b 1Q 1991 Rank2 42
4 b 3Q 2000 Rank3 66
5 a 4Q 1991 Rank1 55
6 c 1Q 2005 rank3 44
I dont even know how to start building this.
Every bit of help is much appreciated.
Thanks