12.8 Launch Angles and Exit Velocities, Revisited
Consider what happens when we ask the database to give us all the data for a particular player, say Pete Alonso, in a particular year, say 2021.
read_bip_data <- function(tbl, begin, end = begin,
batter_id = 624413) {
x <- tbl |>
mutate(year = year(game_date)) |>
group_by(year) |>
filter(type == "X", year >= begin, year <= end) |>
select(
year, game_date, batter, launch_speed, launch_angle,
estimated_ba_using_speedangle,
estimated_woba_using_speedangle
)
if (!is.null(batter_id)) {
x <- x |>
filter(batter == batter_id)
}
x |>
collect()
}
pete_alonso_res <- read_rds('./data/pete_alonso_res.rds')
pete_alonso_res |>
knitr::kable()
expression | min | median | itr/sec | mem_alloc | gc/sec | n_itr | n_gc |
---|---|---|---|---|---|---|---|
nrow(read_bip_data(events_db, 2021)) | 0.030 | 0.0303 | 32.52 | 9.75e+05 | 8.13 | 4 | 1 |
nrow(read_bip_data(sc_arrow, 2021)) | 0.194 | 0.1940 | 5.16 | 9.24e+05 | 7.73 | 2 | 3 |
nrow(read_bip_data(sc_tbl, 2021)) | 0.219 | 0.2510 | 4.04 | 3.50e+08 | 0.00 | 5 | 0 |