标签:http os io ar for cti sp on c
> dtm <- DocumentTermMatrix(corpus)
Error: 不是所有的inherits(doc, "TextDocument")都是TRUE
Solution:
It seems this would have worked just fine in tm 0.5.10
but changes in tm 0.6.0
seems to have broken it. The problem is that the functions tolower
and trim
won‘t necessarily return TextDocuments (it looks like the older version may have automatically done the conversion). They instead return characters and the DocumentTermMatrix isn‘t sure how to handle a corpus of characters.
So you could change to
corpus_clean <- tm_map(news_corpus, content_transformer(tolower))
Or you can run
corpus_clean <- tm_map(corpus_clean, PlainTextDocument)
after all of your non-standard transformations (those not in getTransformations()
) are done and just before you create the DocumentTermMatrix. That should make sure all of your data is in PlainTextDocument and should make DocumentTermMatrix happy.
From: http://stackoverflow.com/questions/24191728/documenttermmatrix-error-on-corpus-argument
R - package'tm' DocumentTermMatrix get error
标签:http os io ar for cti sp on c
原文地址:http://www.cnblogs.com/liuchuanqew/p/3952249.html