I have a data frame that looks like the following:
team playername points
team1 player1     80
team1 player2     40
...
team2 player1     98
...
team20 player1    40
It has 3 columns, the team name, player name, and the total points that player has scored. What I want to do is loop through the data frame and calculate the sum on a per team basis. So team1's total points would be 120 in the following example. I wrote some test code earlier to try to get some output:
curTeam = ""
count = 0
for (i in df) {
    if (curTeam == i$Team) {
        count = count + i$points
    } else {
        print (count)
        curTeam = i$Team
        count = i$points
    }
}
I'm getting the following error:
$ operator is invalid for atomic vectors
Is there a better way to do what I'm trying to do?
Thanks.
 
    