Document-Term-Matrix of tm Package in R

房东的猫 提交于 2019-12-11 20:22:42

问题


I am using document term matrix of tm package in R. I faced an error saying:

Doc <- DocumentTermMatrix(Data)
Error in UseMethod("TermDocumentMatrix", x) : 

no applicable method for 'TermDocumentMatrix' applied to an object of class "table"

I tried data frame, data table, matrix and table but I faced the error again and again. Could you please tell me what should I do?


回答1:


You missed a step... you have to create a "corpus" first...

library("tm")
txt <- c("some text", "here in this", "vector as an example")
corpus <- Corpus(VectorSource(txt))
tdm <- TermDocumentMatrix(corpus)


来源:https://stackoverflow.com/questions/28863145/document-term-matrix-of-tm-package-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!