I got the below R code from online and tried to run, but keep getting an error: Error: failed to load external entity "http://www.baseball-reference.com/teams/ARI/1998-schedule-scores.shtml". Any suggestions to fix?
library("XML")
fetch <- function(team, year) {
url <- paste0("http://www.baseball-reference.com/teams/", team, "/", year, "-schedule-scores.shtml")
raw <- readHTMLTable(url, stringsAsFactors = FALSE)
if (ncol(raw[[6]]) == 21) {
data <- raw[[6]]
} else {
data <- raw[[7]]
}
data$year <- year
data
}
# 1 - Arizona Diamondbacks
ARI <- rbind(fetch("ARI", 1998), fetch("ARI", 1999), fetch("ARI", 2000), fetch("ARI", 2001), fetch("ARI", 2002),
fetch("ARI", 2003), fetch("ARI", 2004), fetch("ARI", 2005), fetch("ARI", 2006), fetch("ARI", 2007),
fetch("ARI", 2008), fetch("ARI", 2009), fetch("ARI", 2010), fetch("ARI", 2011), fetch("ARI", 2012),
fetch("ARI", 2013), fetch("ARI", 2014))
save(ARI, file="data/raw/ARI.rda")