24 lines
604 B
R
24 lines
604 B
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"))
|
|
football_data_ext <- football_data %>%
|
|
select(2:5) %>% 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() |