#' Metric Maximum Calculation for MLB Triple Crown Data
#'
#' @param League AL/NL
#'
#' @return
#' @export
#'
#' @examples
#' League <- 'AL'
#' MLB_TripleCrown_Stat(League)
MLB_TripleCrown_Stat <- function(League){
data <- MLB_Triple_Crown(League)
#HR
HR.data <- as.data.frame(sapply(data[,'HR'], as.numeric))
HR.data1 <- na.omit(HR.data)
colnames(HR.data1) <- c("HR")
max.HR.data <- max(HR.data1)
where.HR.max <- which.max(HR.data1[,"HR"])
#RBI
RBI.data <- as.data.frame(sapply(data[,'RBI'], as.numeric))
RBI.data1 <- na.omit(RBI.data)
colnames(RBI.data1) <- c("RBI")
max.RBI.data <- max(RBI.data1)
where.RBI.max <- which.max(RBI.data1[,"RBI"])
#BA
BA.data <- as.data.frame(sapply(data[,'BA'], as.numeric))
BA.data1 <- na.omit(BA.data)
colnames(BA.data1) <- c("BA")
max.BA.data <- max(BA.data1)
where.BA.max <- which.max(BA.data1[,"BA"])
final.HR <- sprintf(paste("The Triple Crown winner from the", League, "with the most home runs is", data[where.HR.max,2], "with", max.HR.data, "home runs in", data[where.HR.max,1]))
final.RBI <- sprintf(paste("The Triple Crown winner from the", League, "with the most runs batted in is", data[where.RBI.max,2], "with", max.RBI.data, "runs batted in in", data[where.RBI.max,1]))
final.BA <- sprintf(paste("The Triple Crown winner from the", League, "with the highest batting average is", data[where.BA.max,2], "with a batting average of", max.BA.data, "in", data[where.BA.max,1]))
final <- c(final.HR, final.RBI, final.BA)
return(final)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.