data(AwardsPlayers)
# Which awards have been given and how many?
with(AwardsPlayers, table(awardID))
awardtab <- with(AwardsPlayers, table(awardID))
library('lattice')
dotplot(awardtab)
# Restrict to MVP awards
mvp <- subset(AwardsPlayers, awardID == 'Most Valuable Player')
# Who won in 1994?
mvp[mvp$yearID == 1994L, ]
goldglove <- subset(AwardsPlayers, awardID == 'Gold Glove')
# which players won most often?
GGcount <- table(goldglove$playerID)
GGcount[GGcount>10]
# Triple Crown winners
subset(AwardsPlayers, awardID == "Triple Crown")
# Simultaneous Triple Crown and MVP winners
# (compare merged file to TC)
TC <- subset(AwardsPlayers, awardID == "Triple Crown")
MVP <- subset(AwardsPlayers, awardID == "Most Valuable Player")
keepvars <- c("playerID", "yearID", "lgID.x")
merge(TC, MVP, by = c("playerID", "yearID"))[ ,keepvars]
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Lahman)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Lahman/AwardsPlayers.Rd_%03d_medium.png", width=480, height=480)
> ### Name: AwardsPlayers
> ### Title: AwardsPlayers table
> ### Aliases: AwardsPlayers
> ### Keywords: datasets
>
> ### ** Examples
>
> data(AwardsPlayers)
> # Which awards have been given and how many?
> with(AwardsPlayers, table(awardID))
awardID
ALCS MVP All-Star Game MVP
34 54
Babe Ruth Award Baseball Magazine All-Star
64 1520
Branch Rickey Award Comeback Player of the Year
23 20
Cy Young Award Gold Glove
108 1037
Hank Aaron Award Hutch Award
32 48
Lou Gehrig Memorial Award Most Valuable Player
57 190
NLCS MVP Pitching Triple Crown
38 38
Roberto Clemente Award Rolaids Relief Man Award
45 74
Rookie of the Year Silver Slugger
136 631
TSN All-Star TSN Fireman of the Year
1350 88
TSN Guide MVP TSN Major League Player of the Year
33 80
TSN Pitcher of the Year TSN Player of the Year
135 92
TSN Reliever of the Year Triple Crown
20 17
World Series MVP
62
> awardtab <- with(AwardsPlayers, table(awardID))
> library('lattice')
> dotplot(awardtab)
>
> # Restrict to MVP awards
> mvp <- subset(AwardsPlayers, awardID == 'Most Valuable Player')
> # Who won in 1994?
> mvp[mvp$yearID == 1994L, ]
playerID awardID yearID lgID tie notes
4507 thomafr04 Most Valuable Player 1994 AL <NA> <NA>
4508 bagweje01 Most Valuable Player 1994 NL <NA> <NA>
>
> goldglove <- subset(AwardsPlayers, awardID == 'Gold Glove')
> # which players won most often?
> GGcount <- table(goldglove$playerID)
> GGcount[GGcount>10]
clemero01 hernake01 kaatji01 maddugr01 mayswi01 robinbr01 rodriiv01 smithoz01
12 11 16 18 12 16 13 13
vizquom01
11
>
> # Triple Crown winners
> subset(AwardsPlayers, awardID == "Triple Crown")
playerID awardID yearID lgID tie notes
2 hinespa01 Triple Crown 1878 NL <NA> <NA>
5 oneilti01 Triple Crown 1887 AA <NA> <NA>
9 duffyhu01 Triple Crown 1894 NL <NA> <NA>
11 lajoina01 Triple Crown 1901 AL <NA> <NA>
103 cobbty01 Triple Crown 1909 AL <NA> <NA>
556 hornsro01 Triple Crown 1922 NL <NA> <NA>
672 hornsro01 Triple Crown 1925 NL <NA> <NA>
1068 foxxji01 Triple Crown 1933 AL <NA> <NA>
1069 kleinch01 Triple Crown 1933 NL <NA> <NA>
1121 gehrilo01 Triple Crown 1934 AL <NA> <NA>
1275 medwijo01 Triple Crown 1937 NL <NA> <NA>
1541 willite01 Triple Crown 1942 AL <NA> <NA>
1798 willite01 Triple Crown 1947 AL <NA> <NA>
2086 mantlmi01 Triple Crown 1956 AL <NA> <NA>
2567 robinfr02 Triple Crown 1966 AL <NA> <NA>
2624 yastrca01 Triple Crown 1967 AL <NA> <NA>
5914 cabremi01 Triple Crown 2012 AL <NA> <NA>
>
> # Simultaneous Triple Crown and MVP winners
> # (compare merged file to TC)
> TC <- subset(AwardsPlayers, awardID == "Triple Crown")
> MVP <- subset(AwardsPlayers, awardID == "Most Valuable Player")
> keepvars <- c("playerID", "yearID", "lgID.x")
> merge(TC, MVP, by = c("playerID", "yearID"))[ ,keepvars]
playerID yearID lgID.x
1 cabremi01 2012 AL
2 foxxji01 1933 AL
3 hornsro01 1925 NL
4 mantlmi01 1956 AL
5 medwijo01 1937 NL
6 robinfr02 1966 AL
7 yastrca01 1967 AL
>
>
>
>
>
>
>
> dev.off()
null device
1
>