I'm attempting to keep track of a team's cumulative travel throughout a season, but having trouble trying to figure out the best way to do that since teams change who is home/away throughout the season.
Here is my dataframe:
df <- data.frame(game_id = c('1', '2', '3'),
Home_Abbr = c('PHI', 'DAL', 'PIT'),
Away_Abbr = c('DAL', 'PIT', 'PHI'),
Home_Travel = c('0', '0', '0'),
Away_Travel = c('1000', '500', '750'))
Here is what I would like:
| game_id | Home_Abbr | Away_Abbr | Home_Travel | Away_Travel | Home_Cum_Travel | Away_Cum_Travel |
|---|---|---|---|---|---|---|
| 1 | PHI | DAL | 0 | 1000 | 0 | 1000 |
| 2 | DAL | PIT | 0 | 500 | 1000 | 500 |
| 3 | PIT | PHI | 0 | 750 | 500 | 750 |