mardi 9 juin 2015

Sequential numbering in R to create Games out of Matches [duplicate]

This question already has an answer here:

Some background information: I have a rather large data set that includes two columns, a "MatchID" (unique ID for a MATCH) and "GameID" (unique ID for each game). I am looking to create a new column in R. This column will be a "Game Number" column, which will be a sequential count of games played within a match.

e.g.

df$GameNumber <- ifelse (df$GameID == prev_row_value df$GameID,
    (Game Number == (prev_row_vale Game Number) + 1), 1)

essentially, looking to see if GameID matches, if so, than sequential counting, if not restart at 1.

Thanks for the help.

Aucun commentaire:

Enregistrer un commentaire