Skip to content

Analyze XML data

1 message · skyjo

#
I would like to analyze XML data from MLB's website. I do the following
steps:

library(XML)
dat<-"http://gd2.mlb.com/components/game/mlb/year_2007/month_05/day_02/gid_2007_05_02_arimlb_lanmlb_1/inning/inning_1.xml"
example<- xmlTreeParse(dat, useInternalNodes=T)
ex<-xpathApply(example, "//inning", xmlToList)      #could also use
"//atbat"

This brings information from the first inning of the Arizona/LA game played
on 5/2/2007 into R.
Now that I have it in R, I don't understand how to 'get at' the data. For
example, how could I calculate the average start speed (
[[1]]$top$atbat$pitch["start_speed"] ) of all pitches thrown in the inning? 

Thanks, 
Skyler