I need to find a way to selectively sum rows by a index. Here is an example r dataset:
Year  Category  Value  Index 
2002   A         100     1 
2002   B         200     1
2002   C         300     1
2002   A         400     2
2002   B         700     2
2002   C         900     2
2002   A         600     1  
2002   B         500     1
2002   C         400     1
2003   A         100     3 
2003   B         200     3
2003   C         300     3
2003   A         400     2
2003   B         700     2
2003   C         900     2
2003   A         600     2  
2003   B         500     2
2003   C         400     2
I'm hoping to get:
Year  Category  Value  Index 
2002   A         700     1 
2002   B         700     1
2002   C         700     1
2002   A         400     2
2002   B         700     2
2002   C         900     2
2003   A         100     3 
2003   B         200     3
2003   C         300     3
2003   A         1000    2
2003   B         1200    2
2003   C         1300    2
Basically, they will only sum up with the same index by category with different years. Is there an efficient way to do that instead of looping around? I got a long list of index here so I think looping around will be a bad idea.
 
     
    