【问题标题】:Issues with readHTMLTable in RR 中 readHTMLTable 的问题
【发布时间】:2015-01-06 12:48:30
【问题描述】:

我试图使用 readHTMLTable 将一些数据存储在 R Studio 的数据框中,但它一直告诉我找不到函数“ReadHTMLTable”。我不明白我哪里做错了。有人可以花很多时间告诉我如何解决这个问题吗?或者如果它适用于您的 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"

【问题讨论】:

    标签: html r analysis


    【解决方案1】:

    您正在阅读带有 R 默认值的表格,它将字符转换为因子。您可以在readHTMLTable 中使用stringsAsFactors = FALSE,这将传递给data.frame。该表还使用逗号表示您需要删除的千位分隔符:

    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
    

    【讨论】:

    • 所以我复制并粘贴了整个内容,它仍然告诉我找不到函数 readHTMLTable。我不明白为什么函数没有退出。
    【解决方案2】:

    问题是你没有初始化de XML库

    library(XML)
    

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多