Learn R Programming

Lahman (version 1.0-8)

Teams: Teams table

Description

Yearly statistics and standings for teams

Usage

data(Teams)

Arguments

source

Lahman, S. (2010) Lahman's Baseball Database, 1871-2010, v.5.8, http://baseball1.com/statistics/

Details

Variables X2B and X3B are named 2B and 3B in the original database

Examples

Run this code
data(Teams)

# subset on a few variables
teams <- subset(Teams, lgID %in% c("AL", "NL"))
teams <- subset(teams, yearID>1900)
# drop some variables
teams <- subset(teams, select=-c(Ghome,divID,DivWin:WSWin,name,park,teamIDBR:teamIDretro))
teams <- subset(teams, select=-c(HBP,CS,BPF,PPF))

# subset to remove infrequent teams
tcount <- table(teams$teamID)
teams <- subset(teams, teams$teamID %in% names(tcount)[tcount>10], drop=TRUE)
teams$teamID <- factor(teams$teamID, levels=names(tcount)[tcount>10])

# relevel lgID
teams$lgID <- factor(teams$lgID, levels= c("AL", "NL"))
# create new variables

teams <- within(teams, {
   WinPct = W / G    ## Winning percentage
   })

library(lattice)
xyplot(attendance/1000 ~ WinPct|yearID, groups=lgID, data=subset(teams, yearID>1980), 
	type=c("p", "r"), col=c("red","blue"))

if(require(googleVis)) {
motion1 <- gvisMotionChart(teams, idvar='teamID', timevar='yearID',
	chartid="gvisTeams", options=list(width=700, height=600))
plot(motion1)
#print(motion1, file="gvisTeams.html")
}

Run the code above in your browser using DataLab