-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_team_info.R
34 lines (25 loc) · 958 Bytes
/
get_team_info.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
library(tidyverse)
library(rvest)
library(magrittr)
library(janitor)
team_ids <- readRDS(url("https://github.com/sportsdataverse/softballR-data/raw/main/data/ncaa_team_info.RDS")) %>%
select(team_id, team_name) %>%
distinct()
team_info <- data.frame()
for(i in 1:nrow(team_ids)){
print(i)
url <- paste0("https://stats.ncaa.org/teams/history/WSB/", team_ids$team_id[i])
table <- url %>%
read_html() %>%
html_table() %>%
extract2(1) %>%
clean_names() %>%
mutate(season = paste0(substr(year, 1, 2), substr(year, 6, 7)),
team_name = team_ids$team_name[i],
team_id = team_ids$team_id[i]) %>%
rename(head_coach = head_coaches,
win_perc = wl_percent) %>%
select(team_name, team_id, season, head_coach, division, conference, wins, losses, ties, win_perc)
team_info <- rbind(team_info, table)
}
saveRDS(team_info, "~/Projects/softballR-data/data/ncaa_team_info.RDS")