#' Metric Calculation for MLB Season Batting and Pitching Data
#'
#' @param year MLB Season Year
#' @param statistic Batting or Pitching Statistic of Interest
#' @param BorP Batting or Pitching Data
#'
#' @return
#' @export
#'
#' @examples
#' year <- 1999
#' statistic <- "ERA"
#' BorP <- "P"
#' MLB_Season_Stat(year, statistic, BorP)
MLB_Season_Stat <- function(year, statistic, BorP){
data <- MLB_Season(year, BorP)
stat.data <- as.data.frame(sapply(data[,c(statistic)], as.numeric))
stat <- as.character(statistic)
colnames(stat.data) <- c(stat)
max.data <- max(stat.data)
where.max <- which.max(stat.data[,stat])
final <- c(data[where.max,1],max.data)
final2 <- sprintf(paste("The team with the highest", statistic, "in", year, "was the", data[where.max,1], "with a", statistic, "of", max.data))
return(final2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.