acc <-
c(
"North Carolina",
"Duke",
"Wake Forest",
"N.C. State",
"Pittsburgh",
"Virginia Tech",
"Georgia Tech",
"Notre Dame",
"Virginia",
"Boston College",
"Louisville",
"Syracuse",
"Clemson",
"Florida St.",
"Miami FL"
)
acc_team <- function(id) {
kp_team_schedule(team = id, year = 2023)
}
# function to get ACC games
teams_acc <- lapply(acc, acc_team)
# build table of only home conference games
acc_results_2023 <- as.data.frame(do.call(rbind, teams_acc)) %>%
filter(conference_game == TRUE) %>%
filter(!is.na(w_conference)) %>%
mutate(
full_result = str_split(result, ",", simplify = T),
points_for = str_split(full_result[, 2], "-", simplify = T),
fr = full_result[, 1],
pf = points_for[, 1],
pa = points_for[, 2]
) %>%
select(game_date, game_id, team, opponent, location, fr, pf, pa) %>%
mutate(diff = as.numeric(pf) - as.numeric(pa),
year = 2023) %>%
rename(result = fr,
points_scored = pf,
points_allowed = pa) %>%
filter(location == "Home")
home_diff_w <- acc_results_2023 %>%
filter(result == "W") %>%
group_by(team) %>%
summarize(w_diff = sum(diff), W = n())
home_diff_l <- acc_results_2023 %>%
filter(result == "L") %>%
group_by(team) %>%
summarize(l_diff = sum(diff), L = n()) %>%
add_row(team = "Duke", l_diff = 0, L = 0) %>%
add_row(team = "Virginia", l_diff = 0, L = 0)
full_home <- merge(home_diff_w, home_diff_l, by = "team")
h <- full_home %>%
mutate(pd_home = w_diff - l_diff) %>%
select(team, W, L, pd_home) %>%
rename(W_home = W, L_home = L)
# build table of only away conference games
acc_results_2023_away <-
as.data.frame(do.call(rbind, teams_acc)) %>%
filter(conference_game == TRUE) %>%
filter(!is.na(w_conference)) %>%
mutate(
full_result = str_split(result, ",", simplify = T),
points_for = str_split(full_result[, 2], "-", simplify = T),
fr = full_result[, 1],
pf = points_for[, 1],
pa = points_for[, 2]
) %>%
select(game_date, game_id, team, opponent, location, fr, pf, pa) %>%
mutate(diff = as.numeric(pf) - as.numeric(pa),
year = 2023) %>%
rename(result = fr,
points_scored = pf,
points_allowed = pa) %>%
filter(location == "Away")
away_diff_w <- acc_results_2023_away %>%
filter(result == "W") %>%
group_by(team) %>%
summarize(w_diff = sum(diff), W = n()) %>%
add_row(team = "Louisville", w_diff = 0, W = 0) %>%
add_row(team = "Georgia Tech", w_diff = 0, W = 0) %>%
add_row(team = "Notre Dame", w_diff = 0, W = 0)
away_diff_l <- acc_results_2023_away %>%
filter(result == "L") %>%
group_by(team) %>%
summarize(l_diff = sum(diff), L = n())
full_away <- merge(away_diff_w, away_diff_l, by = "team")
away <- full_away %>%
mutate(pd_away = w_diff - l_diff) %>%
select(team, W, L, pd_away) %>%
rename(W_away = W, L_away = L)
total <- merge(h, away, by = "team")
final <- total %>%
mutate(
team = case_match(
team,
"Florida St." ~ "Florida State",
"N.C. State" ~ "NC State",
"Miami FL" ~ "Miami",
team ~ team
)
) %>%
mutate(W = W_home + W_away,
L = L_home + L_away,
delta = pd_home + pd_away) %>%
select(team, W, L, delta, W_home, L_home, pd_home, W_away, L_away, pd_away) %>%
arrange(-delta)