I have a big data set with multiple football matches. Right now the format is wide and I want to count winning streaks, drawing streaks and loosing streaks and teams by their match.
In this case I have the following variables:
- Home_team: a string with a name of a country (Example: England, Spain, etc)
- Away_team: a string with a name of a country (Example: France, Germany, etc)
- Results: a string with three categories (HW: Home win, AW: Away win, D: Draw)
To give a simple example, my data looks something like this:
Home_team <- c("Peru","France","England","Senegal", "Chile", "Colombia","France","Spain","Colombia", "Angola", "Ecuador", "France",
"Peru")
Away_team <- c("Brasil","Germany","Togo","Egypt", "Ecuador", "Argentina","Netherlands","Burkina Faso","New Zealand", "Venezuela", "Portugal", "Canada",
"United States")
Results <- c("HW","HW","AW","D","AW","HW","HW","AW","HW","D","D","HW","D")
df_example <- data.frame(Home_team,Away_team,Results)
df_example
So in this example the following things happened:
- Peru (row 1) had a winning streak of 1 entering the game against the United States and drew the match.
- France entered a winning streak of 2 matches to their game against Canada.
- Colombia would be also entering a 2 game winning streak.
- Ecuador lost against Chile (1 game losing streak) and then drew against Portugal in their next match.
I was thinking that an easier way to do this is put everything in long format and count "Wins", "Losses" and "Draws". And every time the streak stops the counting starts again. But I am not sure if that is the best approach.
The big picture is that I would like to know if streaks (winning, loosing or even drawing) has an effect on the result of the next match.
Any help would be highly appreciated.