Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active August 29, 2015 14:04
Show Gist options
  • Save cpsievert/53d6213011d08475a483 to your computer and use it in GitHub Desktop.
Save cpsievert/53d6213011d08475a483 to your computer and use it in GitHub Desktop.
library(pitchRx)
data(gids, package = "pitchRx")
# Grab gameday identifiers for every Twin's home game in 2012
min.gids <- gids[grepl("2012_[0-9]{2}_[0-9]{2}_[a-z]{6}_minmlb", gids)]
urls <- paste0(pitchRx:::gids2urls(min.gids), "/rawboxscore.xml")
library(XML2R)
obs <- XML2Obs(urls)
nms <- names(obs)
boxscore <- collapse_obs(obs[grepl("^boxscore$", nms)])
attendance <- as.integer(gsub("\\,", "", boxscore[,"attendance"]))
hist(attendance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment