【问题标题】:Error in UseMethod("read_xml") : no applicable method for 'read_xml' applied to an object of class "list"UseMethod(“read_xml”)中的错误:没有适用于“read_xml”的方法应用于“list”类的对象
【发布时间】:2018-11-26 11:45:55
【问题描述】:

我有一些文本文件的向量。这是我的处理方式

text[1] <- read_html("link1") text[2] <- read_html("link2") text[3] <- read_html("link3") . . until text [100]

我想创建一个包含以下内容的语料库:

x <- list(text[i]) z <- lapply(x, read_html)

我明白了

Error in UseMethod("read_xml") : no applicable method for 'read_xml' applied to an object of class "list"

在该错误之前,它是逻辑数据,我已将 text[i] 转换为以下内容

text[i] &lt;- as.character (text[i])

另外,我得到了

number of items to replace is not a multiple of replacement lengthnumber of items to replace is not a multiple of replacement

我无法弄清楚发生了什么。 谢谢。

【问题讨论】:

  • 尝试从x &lt;- list(text[i])中删除[i]
  • 还是有同样的错误。

标签: r text


【解决方案1】:

我试过了:

x <- rep("https://www.google.com/", 3)
z <- lapply(x, read_html)

它有效吗?

【讨论】:

  • 但是我有 100 个不同的 html 链接,我如何通过列出它们来应用它?感谢您的宝贵时间。
  • x 是链接向量。只需将它们放入 x
  • 是的,我想如果我会创建链接的矢量,它会起作用。我有这种向量text[1] &lt;- read_html("link1")。这就是为什么该方法不起作用的原因。
  • 我不明白这个问题。为什么不能将链接放在向量中?
猜你喜欢
  • 2017-12-01
  • 2023-01-22
  • 1970-01-01
  • 2019-09-23
  • 2019-09-12
  • 2022-12-15
  • 2018-03-03
  • 1970-01-01
相关资源
最近更新 更多