39 lines
819 B
R
39 lines
819 B
R
#
|
|
# DATA PROCESSING
|
|
#
|
|
|
|
# Get matches
|
|
getMatchesList <- function(matchesData, first_team, second_team) {
|
|
return(
|
|
matchesData %>%
|
|
filter(home_team %in% c(first_team, second_team)
|
|
& away_team %in% c(first_team, second_team))
|
|
)
|
|
}
|
|
|
|
getMatchesForTeam <- function(matchesData, team) {
|
|
return(
|
|
matchesData %>%
|
|
filter(home_team == team | away_team == team)
|
|
)
|
|
}
|
|
|
|
# Mathes filters
|
|
filterByDate <- function(matchesData, dateFrom, dateTo) {
|
|
return(
|
|
matchesData %>%
|
|
filter(as_date(date) >= dateFrom & as_date(date) <= dateTo)
|
|
)
|
|
}
|
|
|
|
# Get balance
|
|
getBalance <- function(football_data) {
|
|
balance <- football_data %>%
|
|
count(winner, sort = TRUE)
|
|
return(balance)
|
|
}
|
|
|
|
getBalancePercentage <- function(balance) {
|
|
balancePerc <- balance %>%
|
|
mutate(percentage = n/sum(.$n))
|
|
} |