#' Metric Maximum Calculation for MLB Player Batting/Pitching Data
#'
#' @param name Player Name
#' @param statistic Batting/Pitching Statistic of Interest
#'
#' @return
#' @export
#'
#' @examples
#' name <- "Johnny Bench"
#' statistic <- "HR"
#' MLB_Player_Stat_Max(name, statistic)
MLB_Player_Stat_Max <- function(name, statistic){
data <- MLB_Player(name)
stat.data <- as.data.frame(sapply(data[,c(statistic)], as.numeric))
stat.data1 <- na.omit(stat.data)
stat <- as.character(statistic)
colnames(stat.data1) <- c(stat)
max.data <- max(stat.data1)
where.max <- which.max(stat.data1[,stat])
final2 <- sprintf(paste(name, "had the highest", statistic, "of", max.data, "in", data[where.max,1], "with", data[where.max,3]))
return(final2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.