【发布时间】:2022-01-18 15:29:02
【问题描述】:
我的问题是我想将我的语料库传递给 tm 函数 termdocumentmatrix() 并失败并出现错误:Error in UseMethod("meta", x): no applicable method for meta' applied to an object of class "character"。
首先,我有一个名为“auth”的数据框,如下所示:
| Author | Messages |
|---|---|
| 014588 | Hi; How are you |
| 123341 | Hello; Fine u? |
| 857635 | The weather is fine; It looks Sunny; There are some clouds |
作者不言自明,消息均由特定作者撰写。不同的消息由分号分隔。 将数据帧转换为语料库并对其进行清理的代码如下所示:
auth_text <- auth$messages
auth_text2 <- replace_abbreviation(auth_text)
auth_source <- VectorSource(auth_text2)
auth_corp <- VCorpus(auth_source)
clean_corpus <- function(corpus) {
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, PlainTextDocument)
corpus <- tm_map(corpus, removeWords, new_stop)
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, bracketX)
return(corpus)
}
clean_corp <- clean_corpus(auth_corp)
清理语料库后,应由以下人员处理:
corp_tdm <- TermDocumentMatrix(clean_corp)
启动命令后,错误消息弹出如上所述。我什至不能再查看语料库了。谁能帮我解决这个问题?
【问题讨论】:
-
尝试单独运行清理功能并查看语料库消失的位置。我对这一行的猜测:
tm_map(corpus, bracketX)。因为我们不知道bracketX做了什么,所以很难说。还可以尝试使用数据集crude,因为它是 tm 附带的。我们无权访问您的数据。阅读R tag 的信息以及如何制作reproducible example
标签: r tm corpus term-document-matrix