#' Web Scrape for MLB Triple Crown Data
#'
#' @param League MLB League
#'
#' @return
#' @export
#'
#' @importFrom rvest html_table
#' @importFrom xml2 read_html
#' @importFrom purrr set_names
#' @import dplyr
#' @import tidyverse
#' @examples
#' League = 'AL'
#' AL.Triple = MLB_Triple_Crown(League)
MLB_Triple_Crown <- function(League){
TC.html <- read_html("https://www.espn.com/mlb/history/triplecrown")
TC.table <- html_table(TC.html)
TC.data <- as.data.frame(TC.table)
TC.AL <- TC.data[1:10,]
TC.AL1 <- TC.AL[-1,]
TC.AL2 <- TC.AL1 %>%
set_names(TC.AL1[1,])
Triple.Crown.AL <- TC.AL2[-1,]
TC.NL <- TC.data[11:16,]
TC.NL1 <- TC.NL[-1,]
TC.NL2 <- TC.NL1 %>%
set_names(TC.NL1[1,])
Triple.Crown.NL <- TC.NL2[-1,]
if (League == 'AL'){
return(Triple.Crown.AL)
}else if (League == 'NL')
return(Triple.Crown.NL)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.