R/calculate_leaders.R

#' Function To Calculate Leaders
#'
#' This function calculates the leaders of prize categories
#' @keywords calculate leaders prizes
#' @import data.table
#' @export
#' @examples
#' calculate_leaders()

calculate_leaders <- function(AllMatchInfo){

AllMatchInfo <- as.data.table(AllMatchInfo)

GoalsAgainstPerGame <- AllMatchInfo[,.(GoalsAgainstPerGame = sum(ga)/length(match)),
                                    by=.(team)][order(-GoalsAgainstPerGame)]

LatestGoal <- AllMatchInfo[,.(LatestGoal = max(latest_goal,na.rm = TRUE)),
                           by=.(team)][order(-LatestGoal)]

EarliestSubs <- AllMatchInfo[,.(TimeThirdSub = min(third_sub, na.rm = TRUE)),
                             by=.(team)][order(TimeThirdSub)]

MinsPossPerGoal <- AllMatchInfo[,.(MinsPossPerGoal = floor(10*sum(mins_possession)/sum(gf))/10),
                                by=.(team)][order(MinsPossPerGoal)]

return(list("Parking_the_bus" = GoalsAgainstPerGame,
            "Latest_goal" = LatestGoal,
            "Desperation" = EarliestSubs,
            "Making_possession_count" = MinsPossPerGoal))
}
JimmyClowes/wc2018SweepstakeStats documentation built on May 30, 2019, 4:05 a.m.