-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathappendixA.R
50 lines (48 loc) · 1.98 KB
/
appendixA.R
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
# 付録A
library(tidyverse)
source("scripts/parse_retrosheet_pbp.R")
parse_retrosheet_pbp(1950) # 実行して出来たcsvをdataフォルダに移動してください
fields <- read_csv("data/fields.csv")
data <- read_csv("data/all1950.csv",
col_names = pull(fields, Header))
roster <- read_csv("data/roster1950.csv")
headers <- read_csv("data/fields.csv")
pbp2016 <- read_csv("data/all2016.csv",
col_names = pull(headers, Header))
pbp2016 <- pbp2016 %>%
mutate(sequence = gsub("[.>123+*N]", "", PITCH_SEQ_TX))
pbp2016 <- pbp2016 %>%
mutate(c00 = TRUE,
c10 = grepl("^[BIPV]", sequence),
c01 = grepl("^[CFKLMOQRST]", sequence))
pbp2016 <- pbp2016 %>%
mutate(c20 = grepl("^[BIPV]2", sequence),
c30 = grepl("^[BIPV]3", sequence),
c02 = grepl("^[CFKLMOQRST]2", sequence))
b <- "[BIPV]"
s <- "[CFKLMOQRST]"
pbp2016 <- pbp2016 %>%
mutate(c11 = grepl(paste0("^", s, b,
"|", b, s), sequence),
c21 = grepl(paste0("^", s, b, b,
"|", b, s, b,
"|", b, b, s), sequence),
c31 = grepl(paste0("^", s, b, b, b,
"|", b, s, b, b,
"|", b, b, s, b,
"|", b, b, b, s), sequence))
pbp2016 <- pbp2016 %>%
mutate(c12 = grepl(paste0("^", b, s, s,
"|", s, b, s,
"|", s, s, "[FR]*", b), sequence),
c22 = grepl(paste0("^", b, b, s, s,
"|", b, s, b, s,
"|", b, s, s, "[FR]*", b,
"|", s, b, b, s,
"|", s, b, s, "[FR]*", b,
"|", s, s, "[FR]*", b, "[FR]*", b),
sequence),
c32 = grepl(paste0("^", s, "*", b, s,
"*", b, s, "*", b), sequence)
& grepl(paste0("^", b, "*", s, b, "*", s),
sequence))