Created
January 10, 2014 00:14
-
-
Save gghatano/8344614 to your computer and use it in GitHub Desktop.
Scored or not when runner is on third-base (MLB, 2013)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(plyr) | |
# データ読み込み | |
data2013 <- read.csv("all2013.csv") | |
fields <- read.csv("fields.csv") | |
names(data2013) <- fields[,"Header"] | |
# 打者結果だけ | |
data2013 <- subset(data2013, BAT_EVENT_FL == TRUE) | |
# 大チャンス場面かどうかをSuperChanceに入れる | |
data2013$SuperChance <- with(data2013, ifelse(OUTS_CT<2 & BASE3_RUN_ID!="" , 1,0 )) | |
# 大チャンス場面で点が入ったかどうかをSuperChanceScoredに入れる | |
data2013$SuperChanceScored <- with(data2013, ifelse(OUTS_CT<2 & BASE3_RUN_ID!="" & str_detect(EVENT_TX,"3-H"), 1,0 )) | |
# ddplyで要約 | |
data2013.SuperChance <- ddply(data2013, .(BAT_ID), summarize, | |
SuperChance = sum(SuperChance), | |
SuperChanceScored = sum(SuperChanceScored), | |
SuperChanceScoredRate = SuperChanceScored/SuperChance, | |
.progress="text") | |
# 10打席以上 | |
data2013.SuperChance.over10chance <- subset(data2013.SuperChance, SuperChance>10) | |
# 得点ゲット率で並び替え | |
data2013.SuperChance.over10chance.arranged <- arrange(data2013.SuperChance.over10chance, desc(SuperChance)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment