TPD-InternationalFootballRe.../Data/Loader.R

39 lines
936 B
R
Raw Normal View History

# Functions
get_winner_name <- function(match_row) {
if(match_row["home_score"] > match_row["away_score"]) {
return(match_row["home_team"])
}
else if(match_row["home_score"] < match_row["away_score"]) {
return(match_row["away_team"])
}
else {
return("Draw")
}
}
# Load data
football_data <- as_tibble(read.csv("results.csv")) %>%
mutate(winner = apply(., 1, get_winner_name))
# Prepare data
home_teams <- football_data %>%
select("home_team") %>% unique()
away_teams <- football_data %>%
select("away_team") %>% unique()
getDateFromData <- function(matchesData) {
return(
matchesData %>%
select(date) %>%
mutate(date = as.Date(date, "%Y-%m-%d"))
)
}
date_values <- getDateFromData(football_data)
min_date_from <- getDateFromData(football_data) %>%
summarise(min = min(date)) %>% pull()
max_date_to <- getDateFromData(football_data) %>%
summarise(max = max(date)) %>% pull()