Streaks in Individual At-Bats
We can also take a look at streakiness at the at-bat level instead of by game. For this exercise we focus on Ichiro, the true hit king.
load(here::here("data/retro2016.rda"))
ichiro_AB <- retro2016 |>
dplyr::filter(bat_id == "suzui001", ab_fl == TRUE)
ichiro_AB <- ichiro_AB |>
dplyr::mutate(
H = dplyr::if_else(h_fl > 0, 1, 0),
date = stringr::str_sub(game_id, 4, 12),
AB = 1
) |>
dplyr::arrange(date)
## [1] 1 1 2 1 2 1 1 1 1 1 1 2 5 1 3 1 1 1 1 2 2 1 3 1 1 3 1 1 2 2 1 1 2 1 1 1 1 1
## [39] 1 2 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 3 1 1 1 1 1 2 2 1 1 1
Most of Ichiro’s consecutive hit streaks are 1 with the highest being 5. What if we look at streaks where he goes hitless?
ichiro_out <- ichiro_AB |>
dplyr::pull(H) |>
streaks() |>
dplyr::filter(values == 0)
ichiro_out |>
dplyr::pull(lengths)
## [1] 2 1 2 1 4 2 5 2 2 3 4 3 1 1 1 1 11 12 1 2 7 3 1 1 2
## [26] 2 1 1 3 4 1 4 8 1 2 1 4 2 1 1 4 2 7 1 11 4 3 1 10 1
## [51] 3 1 11 8 1 3 6 5 1 3 3 1 1 3 2 1 1 18 2 3
## # A tibble: 12 × 2
## # Groups: lengths [12]
## lengths n
## <int> <int>
## 1 1 26
## 2 2 13
## 3 3 11
## 4 4 7
## 5 5 2
## 6 6 1
## 7 7 2
## 8 8 2
## 9 10 1
## 10 11 3
## 11 12 1
## 12 18 1