Created
October 4, 2022 18:28
-
-
Save mrcaseb/ec1e9ef3bec27b1b41dff90855cd9f95 to your computer and use it in GitHub Desktop.
Load historical game data from 538
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load_538_games <- function(seasons = "SB_ERA"){ | |
s <- nflreadr::csv_from_url("https://projects.fivethirtyeight.com/nfl-api/nfl_elo.csv") |> | |
tibble::as_tibble() |> | |
dplyr::na_if("") |> | |
dplyr::select( | |
season, | |
season_type = playoff, | |
away_team = team2, | |
away_score = score2, | |
home_score = score1, | |
home_team = team1, | |
away_qb = qb2, | |
home_qb = qb1, | |
quality:total_rating | |
) |> | |
dplyr::mutate( | |
away_team = nflreadr::clean_team_abbrs(away_team), | |
home_team = nflreadr::clean_team_abbrs(home_team), | |
season_type = dplyr::case_when( | |
season_type == "c" ~ "CON", | |
season_type == "d" ~ "DIV", | |
season_type == "s" ~ "SB", | |
season_type == "w" ~ "WC", | |
TRUE ~ "REG" | |
) | |
) | |
if(isTRUE(seasons)) return(s) | |
if(seasons == "SB_ERA") return(s |> dplyr::filter(season >= 1967)) | |
s |> dplyr::filter(season %in% seasons) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment