From 9627da7aabeca2c25bf33a70dcfcd025774d0b41 Mon Sep 17 00:00:00 2001 From: Ben Baldwin <1425357+guga31bb@users.noreply.github.com> Date: Mon, 27 Apr 2020 14:49:36 -0400 Subject: [PATCH] Fixes to reconcile with GC and nflscrapR --- R/helper_scrape_rs.R | 29 +++++++++++++++++++++++++++++ R/helper_tidy_play_stats.R | 2 -- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/R/helper_scrape_rs.R b/R/helper_scrape_rs.R index 8ffb0fcc..c04d0d71 100644 --- a/R/helper_scrape_rs.R +++ b/R/helper_scrape_rs.R @@ -78,8 +78,37 @@ get_pbp_rs <- function(gameId) { scoring_team_abbr = scoring_team_id, scoring_team_id = scoring_team_eid, quarter_end = end_quarter + ) %>% + dplyr::mutate( + # Fill in the rows with missing posteam with the lag: + posteam = dplyr::if_else( + (quarter_end == 1 | play_type == "TIMEOUT"), + dplyr::lag(posteam), + posteam), + posteam_id = dplyr::if_else( + (quarter_end == 1 | play_type == "TIMEOUT"), + dplyr::lag(posteam_id), + posteam_id), + yardline = dplyr::if_else( + ((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline)), + dplyr::lag(yardline), + yardline), + yardline_side = dplyr::if_else( + ((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline_side)), + dplyr::lag(yardline_side), + yardline_side), + yardline_number = dplyr::if_else( + ((quarter_end == 1 | play_type == "TIMEOUT") & is.na(yardline_number)), + dplyr::lag(yardline_number), + yardline_number), + yardline_side = dplyr::if_else( + yardline_number == 50, + "MID", + yardline_side + ) ) + # fix for missing quarter in these games if (gameId == 2002090803 | game_info$season[1] == 2000) { plays <- plays %>% dplyr::mutate( diff --git a/R/helper_tidy_play_stats.R b/R/helper_tidy_play_stats.R index a410a033..b7312dba 100644 --- a/R/helper_tidy_play_stats.R +++ b/R/helper_tidy_play_stats.R @@ -318,8 +318,6 @@ sum_play_stats <- function(play_Id, stats) { row$kickoff_out_of_bounds <- 1 row$kickoff_attempt <- 1 row$return_team <- play_stats$teamAbbr[index] - row$kicker_player_id <- play_stats$player.esbId[index] - row$kicker_player_name <- play_stats$player.displayName[index] } else if (play_stats$statId[index] == 50) { row$kickoff_fair_catch <- 1 row$kickoff_attempt <- 1