data(People); data(Batting)
## add player's name to Batting data
People$name <- paste(People$nameFirst, People$nameLast, sep=" ")
batting <- merge(Batting,
People[,c("playerID","name")],
by="playerID", all.x=TRUE)
## batting and throwing
# right-handed batters are much less ambidexterous in throwing than left-handed batters
# (should only include batters)
BT <- with(People, table(bats, throws))
require(vcd)
structable(BT)
mosaic(BT, shade=TRUE)
## Who is Shoeless Joe Jackson?
subset(People, nameLast=="Jackson" & nameFirst=="Joe")
subset(People, nameLast=="Jackson" & nameFirst=="Shoeless Joe")
joeID <-c(subset(People, nameLast=="Jackson" & nameFirst=="Shoeless Joe")["playerID"])
subset(Batting, playerID==joeID)
subset(Fielding, playerID==joeID)
Run the code above in your browser using DataLab