简体   繁体   English

R中的readHTMLTable问题

[英]Issues with readHTMLTable in R

I was trying to use readHTMLTable to store some data in a dataframe in R Studio, but it just keeps telling me could not find function "ReadHTMLTable". 我试图使用readHTMLTable将一些数据存储在R Studio的数据框中,但它只是告诉我找不到函数“ReadHTMLTable”。 I don't understand where I did wrong. 我不明白我做错了什么。 Can someone take a lot at this and tell me how I can fix this? 有人可以对此采取很多措施,并告诉我如何解决这个问题? or if it works in your R studio. 或者如果它在您的R工作室中有效。

url <- 'http://www.cdc.gov/vhf/ebola/outbreaks/2014-west-africa/case-counts.html'
ebola <- getURL(url)
ebola <- readHTMLTable(ebola, stringAsFactors = F)

Error: could not find function "readHTMLTable"

You are reading the table in with R default which converts characters to factors. 您正在使用R default读取表格,该默认值将字符转换为因子。 You can use stringsAsFactors = FALSE in readHTMLTable and this will be passed to data.frame . 您可以在readHTMLTable使用stringsAsFactors = FALSE ,这将传递给data.frame Also the table uses commas for thousand seperators which you will need to remove : 此表也使用逗号分隔千位分隔符,您需要删除它们:

library(XML)
url1 <-'http://en.wikipedia.org/wiki/List_of_Ebola_outbreaks'
df1<- readHTMLTable(url1, which = 2, stringsAsFactors = FALSE)
df1$"Human death"
mySum <- sum(as.integer(gsub(",", "", df1$"Human death")))
> mySum
[1] 6910

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM