Hi, I want to build the table of a football league with 11 teams. All play together. So will 55 games. Since there are an odd number of teams in each round a team will not play. The games will be: games = urnsamples(1:11, x = c('A','B','C','D','E','F','G','H','I','J','K'), size=2, replace=F, ordered=FALSE) games As will be five games per round. How to build a table with all the championship rounds, automatically? I thought about something like: game1 = c( sample(11,2) sample(11,2) sample(11,2) sample(11,2) sample(11,2) ) but, isn't work very well. Some suggestion? -------------------------------------- Silvano Cesar da Costa Departamento de Estat?stica Universidade Estadual de Londrina Fone: 3371-4346
Nice question Silvano ! teams <- LETTERS[1:11] matches <- combn(teams, 2) draw <- data.frame(team1=matches[1,], team2=matches[2,], round=sequence(10:1) + rep(0:9, times=10:1)) Is there a prize :-) Michael On 13 August 2010 21:30, Silvano <silvano at uel.br> wrote:> Hi, > > I want to build the table of a football league with 11 teams. All play > together. So will 55 games. > Since there are an odd number of teams in each round a team will not play. > The games will be: > > games = urnsamples(1:11, x = c('A','B','C','D','E','F','G','H','I','J','K'), > size=2, replace=F, > ordered=FALSE) > games > > As will be five games per round. How to build a table with all the > championship rounds, automatically? > I thought about something like: > > game1 = c( > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > ) > > but, isn't work very well. > > Some suggestion? > > -------------------------------------- > Silvano Cesar da Costa > Departamento de Estat?stica > Universidade Estadual de Londrina > Fone: 3371-4346 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Silvano <silvano <at> uel.br> writes:> > Hi, > > I want to build the table of a football league with 11 > teams. All play together. So will 55 games. > Since there are an odd number of teams in each round a team > will not play.The easy solution is moving around a table with one team pausing. ---- # Playing schedule for an odd number of teams n <- 5 noTeams <- 2*n+1 noGames <- n*noTeams teams <- paste("T", 1:noTeams, sep="") rounds <- numeric(noGames) team1 <- team2 <- character(noGames) for (i in 1:noTeams) { for (j in 1:n) { k <- n*(i-1)+j rounds[k] <- i team1[k] <- teams[j+1] team2[k] <- teams[noTeams-j+1] } teams <- c(teams[2:noTeams], teams[1]) } schedule <- data.frame(rounds=rounds, team1=team1, team2=team2) ---- Hans Werner> The games will be: > > games = urnsamples(1:11, x = > c('A','B','C','D','E','F','G','H','I','J','K'), size=2, > replace=F, > ordered=FALSE) > games > > As will be five games per round. How to build a table with > all the championship rounds, automatically? > I thought about something like: > > game1 = c( > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > ) > > but, isn't work very well. > > Some suggestion? > > -------------------------------------- > Silvano Cesar da Costa > Departamento de Estat?stica > Universidade Estadual de Londrina > Fone: 3371-4346 > >
How about: tmp <- expand.grid(one = 1:11, two = 1:11) tmp$week <- ( ( tmp$one + tmp$two ) %% 11 ) + 1 # reformat for simplicity tmp2 <- tmp[ order(tmp$week), ] tmp3 <- tmp2[ tmp2$one < tmp2$two , ] ### do some checks to make sure everyone plays everyone ### exactly once and each team plays at most 1 game per week. table(tmp3$week) dim(tmp3) with(tmp3, table(one,two)) with(tmp3, table(one,week)) with(tmp3, table(two,week)) reformatting to the desired structure is left to the user. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Silvano > Sent: Friday, August 13, 2010 5:31 AM > To: r-help at r-project.org > Subject: [R] Games > > Hi, > > I want to build the table of a football league with 11 > teams. All play together. So will 55 games. > Since there are an odd number of teams in each round a team > will not play. > The games will be: > > games = urnsamples(1:11, x > c('A','B','C','D','E','F','G','H','I','J','K'), size=2, > replace=F, > ordered=FALSE) > games > > As will be five games per round. How to build a table with > all the championship rounds, automatically? > I thought about something like: > > game1 = c( > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > sample(11,2) > ) > > but, isn't work very well. > > Some suggestion? > > -------------------------------------- > Silvano Cesar da Costa > Departamento de Estat?stica > Universidade Estadual de Londrina > Fone: 3371-4346 > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.