I want a formula/piece of code written to calculate a teams win/loss streak from the attached R file.
1. Sort dataset based on team_id
2. Calculate the number of consecutive wins or losses from the team_outcome column based upon team_id.
So for instance, a team with 3 wins in a row would show 1,2,3 down the column. If the team then went on a 3 game losing streak, the next 3 rows would be -1,-2,-3 etc.
As there are 30 teams in the dataset, when the team_id changes (say from Atlanta to Boston), the streak would reset.