TPD-InternationalFootballRe.../Data/Loader.R
2019-05-19 00:07:35 +02:00

45 lines
1.1 KiB
R

# 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", encoding = "UTF-8")) %>%
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()
teams <- merge(home_teams, away_teams,
by.x = "home_team", by.y = "away_team")
tournament_types <- football_data %>%
pull(tournament) %>% unique() %>% sort()
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()