Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...