11.10 Calculating Basic Park Factors
Retrosheets from 1990 to 1999 season
# retro_data <- baseballr::retrosheet_data(
# path_to_directory = here::here("data/retrosheet"),
# 1990:1999
# )
#
# events <- retro_data |>
# map(pluck, "events") |>
# bind_rows() |>
# as_tibble()
#
# con |>
# dbWriteTable(name = "events", value = events)
# events_db <- con |>
# tbl("events")
Select the columns containing the home and away teams and the event code from the events table, keeping only the rows where the year is 1996 and the event code corresponds to one indicating a batted ball.
# query <- '
# SELECT "away_team_id", LEFT("game_id", 3) AS "home_team_id", "event_cd"
# FROM "events"
# WHERE "year" = 1996
# AND "event_cd" IN (2, 18, 19, 20, 21, 22, 23);
# '
# hr_PF <- dbGetQuery(con, query)
hr_PF <- read_rds('./data/hr_PF.rds')
dim(hr_PF)
## [1] 130437 3
## away_team_id home_team_id event_cd
## 1 SFN ATL 2
## 2 SFN ATL 2
## 3 SFN ATL 18
## 4 SFN ATL 2
## 5 SFN ATL 23
## 6 SFN ATL 2