Skip to content

Instantly share code, notes, and snippets.

@EmilHvitfeldt
Created October 11, 2023 22:16
Show Gist options
  • Save EmilHvitfeldt/f0f7d96894295c3bf5686f2707dce855 to your computer and use it in GitHub Desktop.
Save EmilHvitfeldt/f0f7d96894295c3bf5686f2707dce855 to your computer and use it in GitHub Desktop.
2 Times Winner of SuperBowl
library(tidyverse)
library(rvest)

url <- "http://www.allcompetitions.com/nfl_sbros.php"

res <- read_html(url) |>
  html_element("table:nth-of-type(2)") |>
  html_table() |>
  set_names("teams")

res$teams |>
  str_remove(".*?: ") |>
  str_remove(". \\(.*") |>
  str_split(", ") |>
  unlist() |>
  as_tibble() |>
  set_names("player") |>
  count(player, sort = TRUE) |>
  count(n) |>
  print() |>
  count(n >= 2, wt = nn, sort = TRUE) |>
  mutate(prop = n / sum(n))
#> Storing counts in `nn`, as `n` already present in input
#> ℹ Use `name = "new_name"` to pick a new name.
#> # A tibble: 6 × 2
#>       n    nn
#>   <int> <int>
#> 1     1  1438
#> 2     2   358
#> 3     3    91
#> 4     4    28
#> 5     5     1
#> 6     7     2
#> # A tibble: 2 × 3
#>   `n >= 2`     n  prop
#>   <lgl>    <int> <dbl>
#> 1 FALSE     1438 0.750
#> 2 TRUE       480 0.250

Created on 2023-10-11 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment