I'm trying to write a program that generates a fixture list for a sports league. If each team played each other home and away like in the English Premier League, this would be easy (expand_grid()
or crossing()
would be perfect), but this one is more complex.
I have a 17-team competition where each team plays 24 matches (12 at home and 12 away) for a total of 204 matches across the season. Each team will play 8 teams twice (home and away) and the other 8 teams only once (four at home and four away).
I cannot for the life of me work this out. All my attempts have basically started like this:
library(tidyverse)
# 17 team names
teams <- c(paste("Team", LETTERS[1:17]))
# Combinations of different teams
matches <- expand_grid(home = teams, away = teams) |>
filter(home != away)
The issue now is that I don't know how to filter this down so each team will have only the 24 games. My focus on getting it to work for a given team obviously affects the number of matches the other team in the matchup is involved in. I don't know how to control this. I've tried sampling methods but this is giving me variability in how many games each team is left with.
Do any of you rstats geniuses out there know how to crack this?
Appreciate any help!
Aucun commentaire:
Enregistrer un commentaire