码迷,mamicode.com
首页 > 其他好文 > 详细

R - package'tm' DocumentTermMatrix get error

时间:2014-09-02 21:15:55      阅读:182      评论:0      收藏:0      [点我收藏+]

标签: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 trimwon‘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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!