Skip to contents

Compute various NFL stats based off nflverse Play-by-Play data.

Usage

calculate_stats(
  seasons = nflreadr::most_recent_season(),
  summary_level = c("season", "week"),
  stat_type = c("player", "team"),
  season_type = c("REG", "POST", "REG+POST")
)

Arguments

seasons

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.

summary_level

Summarize stats by "season" or "week".

stat_type

Calculate "player" level stats or "team" level stats.

season_type

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".

Value

A tibble of player/team stats summarized by season/week.

See also

nfl_stats_variables for a description of all variables.

https://www.nflfastr.com/articles/stats_variables.html for a searchable table of the stats variable descriptions.

Examples

# \donttest{
try({# to avoid CRAN test problems
stats <- calculate_stats(2023, "season", "player")
dplyr::glimpse(stats)
})
#> Rows: 1,943
#> Columns: 113
#> $ player_id                   <chr> "00-0022531", "00-0023459", "00-0023853", …
#> $ player_name                 <chr> "J.Peters", "A.Rodgers", "M.Prater", "M.Le…
#> $ player_display_name         <chr> "Jason Peters", "Aaron Rodgers", "Matt Pra…
#> $ position                    <chr> "T", "QB", "K", "TE", "K", "K", "LS", "QB"…
#> $ position_group              <chr> "OL", "QB", "SPEC", "TE", "SPEC", "SPEC", …
#> $ headshot_url                <chr> "https://static.www.nfl.com/image/upload/f…
#> $ season                      <int> 2023, 2023, 2023, 2023, 2023, 2023, 2023, …
#> $ season_type                 <chr> "REG", "REG", "REG", "REG", "REG", "REG", …
#> $ recent_team                 <chr> "SEA", "NYJ", "ARI", "CHI", "TEN", "NYG", …
#> $ games                       <int> 2, 1, 17, 6, 17, 3, 2, 5, 1, 16, 5, 15, 2,…
#> $ completions                 <int> 0, 0, 0, 0, 0, 0, 0, 123, 0, 0, 0, 326, 23…
#> $ attempts                    <int> 0, 1, 0, 0, 0, 0, 0, 204, 0, 0, 0, 521, 42…
#> $ passing_yards               <int> 0, 0, 0, 0, 0, 0, 0, 1616, 0, 0, 0, 3965, …
#> $ passing_tds                 <int> 0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 24, 0, 0…
#> $ passing_interceptions       <int> 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 11, 2, 0,…
#> $ sacks_suffered              <int> 0, 1, 0, 0, 0, 0, 0, 8, 0, 0, 0, 30, 1, 0,…
#> $ sack_yards_lost             <int> 0, -10, 0, 0, 0, 0, 0, -57, 0, 0, 0, -205,…
#> $ sack_fumbles                <int> 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, …
#> $ sack_fumbles_lost           <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, …
#> $ passing_air_yards           <int> 0, 17, 0, 0, 0, 0, 0, 1910, 0, 0, 0, 4033,…
#> $ passing_yards_after_catch   <int> 0, 0, 0, 0, 0, 0, 0, 678, 0, 0, 0, 1890, 8…
#> $ passing_first_downs         <int> 0, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 187, 14,…
#> $ passing_epa                 <dbl> NA, -2.0319599, NA, NA, NA, NA, NA, -0.554…
#> $ passing_cpoe                <dbl> NA, NA, NA, NA, NA, NA, NA, -2.875606, NA,…
#> $ passing_2pt_conversions     <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, …
#> $ pacr                        <dbl> NA, 0.0000000, NA, NA, NA, NA, NA, 0.84607…
#> $ carries                     <int> 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 21, 3, 0,…
#> $ rushing_yards               <int> 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 65, -3, 0…
#> $ rushing_tds                 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ rushing_fumbles             <int> 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, …
#> $ rushing_fumbles_lost        <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ rushing_first_downs         <int> 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, …
#> $ rushing_epa                 <dbl> NA, NA, NA, NA, NA, NA, NA, -0.469946, NA,…
#> $ rushing_2pt_conversions     <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receptions                  <int> 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ targets                     <int> 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_yards             <int> 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ receiving_tds               <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_fumbles           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_fumbles_lost      <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_air_yards         <int> 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_yards_after_catch <int> 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,…
#> $ receiving_first_downs       <int> 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ receiving_epa               <dbl> NA, NA, NA, 2.486083, NA, NA, NA, NA, NA, …
#> $ receiving_2pt_conversions   <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, …
#> $ racr                        <dbl> NA, NA, NA, 3.2222222, NA, NA, NA, NA, NA,…
#> $ target_share                <dbl> 0.00000000, 0.00000000, 0.00000000, 0.0104…
#> $ air_yards_share             <dbl> 0.000000000, 0.000000000, 0.000000000, 0.0…
#> $ wopr                        <dbl> 0.00000000, 0.00000000, 0.00000000, 0.0173…
#> $ special_teams_tds           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ def_tackles_solo            <int> 0, 0, 0, 0, 0, 0, 1, 0, 1, 25, 4, 0, 0, 0,…
#> $ def_tackles_with_assist     <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 1, 0, 0, 0, …
#> $ def_tackle_assists          <int> 0, 0, 0, 0, 0, 0, 1, 0, 0, 24, 1, 0, 0, 0,…
#> $ def_tackles_for_loss        <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, …
#> $ def_tackles_for_loss_yards  <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0,…
#> $ def_fumbles_forced          <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
#> $ def_sacks                   <dbl> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.…
#> $ def_sack_yards              <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0,…
#> $ def_qb_hits                 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0,…
#> $ def_interceptions           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ def_interception_yards      <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ def_pass_defended           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
#> $ def_tds                     <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ def_fumbles                 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ def_safeties                <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
#> $ misc_yards                  <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fumble_recovery_own         <int> 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, …
#> $ fumble_recovery_yards_own   <int> 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, …
#> $ fumble_recovery_opp         <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
#> $ fumble_recovery_yards_opp   <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, …
#> $ fumble_recovery_tds         <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ penalties                   <int> 2, 0, 0, 2, 0, 0, 0, 1, 0, 1, 2, 3, 0, 0, …
#> $ penalty_yards               <int> 9, 0, 0, 15, 0, 0, 0, 11, 0, 5, 15, 32, 0,…
#> $ punt_returns                <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ punt_return_yards           <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ kickoff_returns             <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ kickoff_return_yards        <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_made                     <int> 0, 0, 28, 0, 29, 5, 0, 0, 0, 0, 0, 0, 0, 1…
#> $ fg_att                      <int> 0, 0, 33, 0, 30, 7, 0, 0, 0, 0, 0, 0, 0, 1…
#> $ fg_missed                   <int> 0, 0, 5, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 5, …
#> $ fg_blocked                  <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, …
#> $ fg_long                     <int> NA, NA, 62, NA, 53, 52, NA, NA, NA, NA, NA
#> $ fg_pct                      <dbl> NA, NA, 0.8484848, NA, 0.9666667, 0.714285…
#> $ fg_made_0_19                <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_made_20_29               <int> 0, 0, 6, 0, 9, 2, 0, 0, 0, 0, 0, 0, 0, 2, …
#> $ fg_made_30_39               <int> 0, 0, 7, 0, 9, 2, 0, 0, 0, 0, 0, 0, 0, 3, …
#> $ fg_made_40_49               <int> 0, 0, 6, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 3, …
#> $ fg_made_50_59               <int> 0, 0, 8, 0, 5, 1, 0, 0, 0, 0, 0, 0, 0, 3, …
#> $ fg_made_60_                 <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_missed_0_19              <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_missed_20_29             <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_missed_30_39             <int> 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, …
#> $ fg_missed_40_49             <int> 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, …
#> $ fg_missed_50_59             <int> 0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, …
#> $ fg_missed_60_               <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ fg_made_list                <chr> NA, NA, "28;54;37;37;44;39;43;62;38;55;32;…
#> $ fg_missed_list              <chr> NA, NA, "55;34;56;43;51", NA, "51", "54;45…
#> $ fg_blocked_list             <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ fg_made_distance            <int> 0, 0, 1174, 0, 1083, 160, 0, 0, 0, 0, 0, 0…
#> $ fg_missed_distance          <int> 0, 0, 239, 0, 51, 99, 0, 0, 0, 0, 0, 0, 0,…
#> $ fg_blocked_distance         <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45,…
#> $ pat_made                    <int> 0, 0, 22, 0, 28, 6, 0, 0, 0, 0, 0, 0, 0, 8…
#> $ pat_att                     <int> 0, 0, 23, 0, 30, 7, 0, 0, 0, 0, 0, 0, 0, 8…
#> $ pat_missed                  <int> 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ pat_blocked                 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ pat_pct                     <dbl> NA, NA, 0.9565217, NA, 0.9333333, 0.857142…
#> $ gwfg_made                   <int> 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, …
#> $ gwfg_att                    <int> 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, …
#> $ gwfg_missed                 <int> 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ gwfg_blocked                <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
#> $ gwfg_distance_list          <chr> NA, NA, "23;51", NA, "41", "54", NA, NA, N
#> $ fantasy_points              <dbl> 0.00, 0.00, 0.00, 8.90, 0.00, 0.00, 0.00, …
#> $ fantasy_points_ppr          <dbl> 0.00, 0.00, 0.00, 12.90, 0.00, 0.00, 0.00,…
# }