Description Usage Format Details Source Examples
Yearly statistics and standings for teams
1 |
A data frame with 2745 observations on the following 48 variables.
yearIDYear
lgIDLeague; a factor with levels AA AL FL NL PL UA
teamIDTeam; a factor
franchIDFranchise (links to TeamsFranchises table)
divIDTeam's division; a factor with levels C E W
RankPosition in final standings
GGames played
GhomeGames played at home
WWins
LLosses
DivWinDivision Winner (Y or N)
WCWinWild Card Winner (Y or N)
LgWinLeague Champion(Y or N)
WSWinWorld Series Winner (Y or N)
RRuns scored
ABAt bats
HHits by batters
X2BDoubles
X3BTriples
HRHomeruns by batters
BBWalks by batters
SOStrikeouts by batters
SBStolen bases
CSCaught stealing
HBPBatters hit by pitch
SFSacrifice flies
RAOpponents runs scored
EREarned runs allowed
ERAEarned run average
CGComplete games
SHOShutouts
SVSaves
IPoutsOuts Pitched (innings pitched x 3)
HAHits allowed
HRAHomeruns allowed
BBAWalks allowed
SOAStrikeouts by pitchers
EErrors
DPDouble Plays
FPFielding percentage
nameTeam's full name
parkName of team's home ballpark
attendanceHome attendance total
BPFThree-year park factor for batters
PPFThree-year park factor for pitchers
teamIDBRTeam ID used by Baseball Reference website
teamIDlahman45Team ID used in Lahman database version 4.5
teamIDretroTeam ID used by Retrosheet
Variables X2B and X3B are named 2B and 3B in the original database
Lahman, S. (2014) Lahman's Baseball Database, 1871-2013, 2014 version, http://baseball1.com/statistics/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 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>15], drop=TRUE)
teams$teamID <- factor(teams$teamID, levels=names(tcount)[tcount>15])
# 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"))
## Not run:
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")
#### merge with ave salary, for those years where salary is available
avesal <- aggregate(salary ~ yearID + teamID, data=Salaries, FUN=mean)
# salary data just starts after 1980
teamsSal <- subset(teams, yearID>=1980)
# add salary to team data
teamsSal <- merge(teamsSal,
avesal[,c("yearID", "teamID", "salary")],
by=c("yearID", "teamID"), all.x=TRUE)
motion2 <- gvisMotionChart(teamsSal, idvar='teamID', timevar='yearID',
xvar="attendance", yvar="salary", sizevar="WinPct",
chartid="gvisTeamsSal", options=list(width=700, height=600))
plot(motion2)
#print(motion2, file="gvisTeamsSal.html")
}
## End(Not run)
|
Loading required package: googleVis
Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
Welcome to googleVis version 0.6.3
Please read Google's Terms of Use
before you start using the package:
https://developers.google.com/terms/
Note, the plot method of googleVis will by default use
the standard browser to display its output.
See the googleVis package vignettes for more details,
or visit https://github.com/mages/googleVis.
To suppress this message use:
suppressPackageStartupMessages(library(googleVis))
starting httpd help server ... done
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.