R, group together two columns with ID, do the cumulative for two colums : I've read through countless posts trying to group together two columns and do the cumulative sum. The closest I've come to is:

ave(contest$loser_points, (contest$loser), FUN=cumsum)

What I however want is something that creates the columns Winner_Total and Loser_Total like below. So when 1 competes in the final match, his points from when he both won and lost are in the loser total column.

I've previously done for loops but because the real dataset is 10,000 rows large it takes so much time.

    Winner Loser Winner_Points Loser_Points Winner_Total Loser_Total
    1      2     5             5            5            5
    2      3     4             2            9            2
    3      1     12            2            14           7
    4      3     2             6            2            20            
    1      3     1             6            8            26
    2      1     6             2            15           10