Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active August 29, 2015 14:03
Show Gist options
  • Save cpsievert/a9fcfca600a9e46142d0 to your computer and use it in GitHub Desktop.
Save cpsievert/a9fcfca600a9e46142d0 to your computer and use it in GitHub Desktop.
devtools::install_github("cpsievert/pitchRx")
library(pitchRx)
library(dplyr)
dat <- scrape(start = "2013-09-01", end = "2013-09-11",
suffix = c("inning/inning_all.xml", "players.xml"))
# note that gameday_link can be used as a "game identifier"
p.data <- dat$pitch %>%
select(des, px, pz, sz_bot, sz_top, pitch_type, gameday_link, num) %>%
filter(des %in% c("Called Strike", "Ball"))
b.data <- dat$atbat %>%
select(b_height, stand, gameday_link, num)
u.data <- dat$umpire %>%
select(position, name, gameday_link) %>%
filter(position=="home")
pub <- p.data %>% merge(u.data, by = "gameday_link") %>%
merge(b.data, by = c("gameday_link", "num")) %>%
select(name, des, px, pz, sz_bot, sz_top, pitch_type, b_height, stand)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment