如何在R中模拟世界杯抽签
因此,明年世界杯的资格赛已经结束,抽签将在几周后举行 根据世界排名,32支球队被分为“pots”,然后被分成小组,这样每个小组都包含来自每个pot的一支球队。很简单如何在R中模拟世界杯抽签,r,algorithm,simulation,R,Algorithm,Simulation,因此,明年世界杯的资格赛已经结束,抽签将在几周后举行 根据世界排名,32支球队被分为“pots”,然后被分成小组,这样每个小组都包含来自每个pot的一支球队。很简单 library(tidyverse) seeds <- read_csv("https://gist.github.com/eldenvo/fb0d27fcb5d322b538d06cdc06b1c559/raw/3eaaab91c29d2dde6c9a28377b325844b834df13/seeds.c
library(tidyverse)
seeds <- read_csv("https://gist.github.com/eldenvo/fb0d27fcb5d322b538d06cdc06b1c559/raw/3eaaab91c29d2dde6c9a28377b325844b834df13/seeds.csv")
head(seeds)
# A tibble: 6 x 4
nation rank pot confed
<chr> <int> <int> <chr>
1 Russia 65 1 Europe
2 Brazil 2 1 South America
3 Iran 34 3 Asia
4 Japan 44 4 Asia
5 Mexico 16 2 North America
6 Belgium 5 1 Europe
groups <- letters[c(1:8)]
draw <- seeds %>% filter(pot == 1) %>% sample_n(8) %>% mutate(group = groups)
for (i in 2:4){
df <- seeds %>% filter(pot == i) %>% sample_n(8) %>% mutate(group = groups)
draw <- bind_rows(draw, df)
}
print(draw)
# A tibble: 32 x 5
nation rank pot confed group
<chr> <int> <int> <chr> <chr>
1 Russia 65 1 Europe a
2 Argentina 4 1 South America b
3 Brazil 2 1 South America c
4 Belgium 5 1 Europe d
5 Portugal 3 1 Europe e
6 Poland 6 1 Europe f
7 Germany 1 1 Europe g
8 France 7 1 Europe h
9 England 12 2 Europe a
10 Uruguay 17 2 South America b
# ... with 22 more rows
库(tidyverse)
种子%变异(组=组)
(我在2:4中){
df%过滤器(pot==i)%%>%样本(8)%%>%变异(组=组)
画