I am scraping the Illinois department of corrections website (https://www2.illinois.gov/idoc/facilities/Pages/Covid19Response.aspx) and trying to create a vector called Staff.Confirmed for the number of staff who have contracted COVID-19. I run the following code
url <- "https://www2.illinois.gov/idoc/facilities/Pages/Covid19Response.aspx"
web <- read_html(url)
Staff.Confirmed.html <- html_nodes(web,'.soi-rteTableOddCol-1:nth-child(2)')
Staff.Confirmed <- html_text(Staff.Confirmed.html)
Staff.Confirmed <- as.numeric(Staff.Confirmed)
which produces the following output when I call Staff.Confirmed:
[1] "1" "1" "1" "4" "5" "7" "1" "1" "2" "1" "13" "3" "4" "2" "4" "2" "0" "8" "8" "1" "79" "37" "0" "1" "1"
However, when I run
Staff.Confirmed <- as.numeric(Staff.Confirmed)
I get the warning message "NAs introduced by coercion." Every number has become an NA. As far as I can tell, there are no whitespaces, nor any other issues which should be causing this. Has anyone else encountered this issue before?
I tried running
Staff.Confirmed <- gsub(pattern="^[0-9]",replacement="",Staff.Confirmed)
Staff.Confirmed <- as.numeric(Staff.Confirmed)
But the same error occurred. Any help would be greatly appreciated! Thank you.