Compute various NFL stats based off nflverse Play-by-Play data.
calculate_stats(
seasons = nflreadr::most_recent_season(),
summary_level = c("season", "week"),
stat_type = c("player", "team"),
season_type = c("REG", "POST", "REG+POST"),
pbp = NULL
)A tibble of player/team stats summarized by season/week.
A numeric vector of 4-digit years associated with given NFL
seasons - defaults to latest season. If set to TRUE, returns all available
data since 1999. Ignored if argument pbp is not NULL.
Summarize stats by "season" or "week".
Calculate "player" level stats or "team" level stats.
One of "REG", "POST", or "REG+POST". Filters
data to regular season ("REG"), post season ("POST") or keeps all data.
Only applied if summary_level == "season".
This argument allows passing a subset of nflverse play-by-play
data, created with build_nflfastR_pbp() or loaded with load_pbp().
Stats are then calculated based on the game_ids and play_ids in this
subset of play-by-play data, rather then using the seasons specified in the
seasons argument. The function will error if required variables are
missing from the subset, but lists which variables are missing.
If pbp = NULL (the default), all available games and plays from the
seasons argument are used to calculate stats.
Please use this responsibly, because the output is structurally identical
to full seasons, even if plays have been filtered out. It may then appear
as if the stats are incorrect. If pbp is not NULL, the function will add
the attribute "custom_pbp" = TRUE to the function output to help identify
stats that are possibly based on play-by-play subsets.
nfl_stats_variables for a description of all variables.
https://nflfastr.com/articles/stats_variables.html for a searchable table of the stats variable descriptions.
# \donttest{
try({# to avoid CRAN test problems
stats <- calculate_stats(2023, "season", "player")
dplyr::glimpse(stats)
})
# }
Run the code above in your browser using DataLab