Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate_series_conversion_rates handles small samples of pbp #417

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: nflfastR
Title: Functions to Efficiently Access NFL Play by Play Data
Version: 4.5.1.9003
Version: 4.5.1.9004
Authors@R:
c(person(given = "Sebastian",
family = "Carl",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- The function `calculate_player_stats()` now summarises target share and air yards share correctly when called with argument `weekly = FALSE` (#413)
- The function `calculate_player_stats()` now returns the opponent team when called with argument `weekly = TRUE` (#414)
- The function `calculate_player_stats_def()` no longer errors when small subsets of pbp data are missing stats. (#415)
- The function `calculate_series_conversion_rates()` no longer returns `NA` values if a small subset of pbp data is missing series on offense or defense. (#417)

# nflfastR 4.5.1

Expand Down
6 changes: 3 additions & 3 deletions R/calculate_series_conversion_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ calculate_series_conversion_rates <- function(pbp,

# Offense + Defense -------------------------------------------------------

combined <- dplyr::left_join(offense, defense, by = c("season", "team", "week"))
combined <- dplyr::full_join(offense, defense, by = c("season", "team", "week"))

if (isFALSE(weekly)){
combined <- combined %>%
dplyr::select(-"week") %>%
dplyr::group_by(.data$season, .data$team) %>%
dplyr::summarise(
dplyr::across(.cols = dplyr::ends_with("_n"), .fns = sum),
dplyr::across(.cols = !dplyr::ends_with("_n"), .fns = mean),
dplyr::across(.cols = dplyr::ends_with("_n"), .fns = ~ sum(.x, na.rm = TRUE)),
dplyr::across(.cols = !dplyr::ends_with("_n"), .fns = ~ mean(.x, na.rm = TRUE)),
.groups = "drop"
) %>%
dplyr::relocate("def_n", .after = "off_to")
Expand Down