##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 05 Jan 2021
# Function: rankODIBowlers
# This function ranks the bowlers
#
#
###########################################################################################
#' @title
#' Ranks the ODI bowlers
#'
#' @description
#' This function creates a single datframe of all ODI bowlers and then ranks them
#' @usage
#' rankODIBowlers(dir=".",odir=".",minMatches=20)
#'
#' @param dir
#' The input directory
#'
#' @param odir
#' The output directory
#'
#' @param minMatches
#' Minimum matches
#'
#'
#' @return The ranked ODI bowlers
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{tvganesh.85@gmail.com}
#'
#' @examples
#' \dontrun{
#' #
#' odiBowlersRank <- rankODIBowlers()
#' }
#'
#' @seealso
#' \code{\link{rankODIBatsmen}}\cr
#' \code{\link{rankT20Batsmen}}\cr
#' @export
#'
rankODIBowlers <- function(dir='.',odir=".",minMatches=20) {
bowlingDetails=bowler=wickets=economyRate=matches=meanWickets=meanER=totalWickets=NULL
wicketPlayerOut=opposition=venue=NULL
currDir= getwd()
teams <-c("Australia","India","Pakistan","West Indies", 'Sri Lanka',
"England", "Bangladesh","Netherlands","Scotland", "Afghanistan",
"Zimbabwe","Ireland","New Zealand","South Africa","Canada",
"Bermuda","Kenya","Hong Kong","Nepal","Oman","Papua New Guinea",
"United Arab Emirates","Namibia","Cayman Islands","Singapore",
"United States of America","Bhutan","Maldives","Botswana","Nigeria",
"Denmark","Germany","Jersey","Norway","Qatar","Malaysia","Vanuatu",
"Thailand")
#Change dir
setwd(odir)
# Compute wickets by bowler in each team
o <- data.frame(bowler=character(0),wickets=numeric(0),economyRate=numeric(0))
for(team1 in teams){
bowlingDetails <- NULL
val <- paste(team1,"-BowlingDetails.RData",sep="")
print(val)
tryCatch(load(val),
error = function(e) {
print("No data1")
setNext=TRUE
}
)
details <- bowlingDetails
bowlingDF <- rbind(bowlingDF,details)
}
# Compute number of matches played
a=bowlingDF %>% select(bowler,date) %>% unique()
b=summarise(group_by(a,bowler),matches=n())
# Compute wickets
c <- filter(bowlingDF,wicketPlayerOut != "nobody")
d <- select(c,bowler,wicketPlayerOut,economyRate,date,opposition,venue)
e <- summarise(group_by(d,bowler,date,economyRate),wickets=length(unique(wicketPlayerOut)))
f=summarise(group_by(e,bowler), totalWickets=sum(wickets),meanER=mean(economyRate))
# Join
g=merge(b,f,by="bowler",all.x = TRUE)
g[is.na(g)] <- 0
h <- filter(g,matches >= minMatches)
setwd(currDir)
ODIBowlersRank <- arrange(h,desc(totalWickets),desc(meanER))
ODIBowlersRank <- distinct(ODIBowlersRank)
ODIBowlersRank
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.