Reading and fixing EPL Dates
3 years ago in Plain Text
rm(list = ls())
library(tidyverse)
library(lubridate)
directory = "D:/Dropbox/Dropbox/Wits 2021/FINE4020/R Group Project/EPL/"
files = list.files(directory)
data_files = files[str_detect(files, ".csv")]
season_list = vector(mode = "list", length = 10)
column_types = "ccccnncnnccnnnnnnnnnnnn"
# First season dates are Year/Month/Day
season_list[[1]] = read_csv(paste0(directory, data_files[1]), col_types = column_types) %>%
mutate(Season = 1, .before = HomeTeam,
Date = ymd(Date))
for(x in 2:9){
season_list[[x]] <- read_csv(paste0(directory, data_files[x]), col_types = column_types) %>%
mutate(Season = x, .before = HomeTeam,
Date = dmy(paste0(str_sub(Date, 3, 8), 20, str_sub(Date, 9, 10))))
}
season_list[[10]] = read_csv(paste0(directory, data_files[10]), col_types = column_types) %>%
mutate(Season = 10, .before = HomeTeam,
Date = dmy(Date))
EPL_df = bind_rows(season_list)