2019-05-15 00:27:04 +02:00
|
|
|
# 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
|
2019-05-15 22:28:34 +02:00
|
|
|
football_data <- as_tibble(read.csv("results.csv")) %>%
|
|
|
|
mutate(winner = apply(., 1, get_winner_name))
|
2019-05-15 00:27:04 +02:00
|
|
|
|
|
|
|
# Prepare data
|
|
|
|
home_teams <- football_data %>%
|
|
|
|
select("home_team") %>% unique()
|
|
|
|
|
|
|
|
away_teams <- football_data %>%
|
2019-05-15 22:28:34 +02:00
|
|
|
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()
|