使用 tm 包和 dtm/wordclouds 抛出新错误 [英] New error being thrown with tm package and dtm/wordclouds

查看:31
本文介绍了使用 tm 包和 dtm/wordclouds 抛出新错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 R(3.2.5) 并加载以下包'SnowballC'、'tm'、'NLP'、'RWeka'、'RTextTools'、'wordcloud'、'fpc'

using R(3.2.5) and with the following packages loaded 'SnowballC', 'tm', 'NLP', 'RWeka', 'RTextTools', 'wordcloud', 'fpc'

carmenCorpus <- Corpus(VectorSource(feedback$Description))
carmenCorpus <- tm_map(carmenCorpus, PlainTextDocument)
carmenCorpus <- tm_map(carmenCorpus, removePunctuation)
carmenCorpus <- tm_map(carmenCorpus, removeWords, stopwords('english'))
carmenCorpus <- tm_map(carmenCorpus, stemDocument)

当我创建 wordcloud 时,出现以下错误.这是一个新错误,几个月前运行代码时没有问题:

When I go to create a wordcloud i get the following error. this is a new error, when the code was run several months ago there was no issue:

wordcloud(carmenCorpus, max.words = 100, random.order = FALSE)

# Error in simple_triplet_matrix(i, j, v, nrow = length(terms), ncol = length(corpus),  : 
#  'i, j' invalid

请就此问题提出建议.

推荐答案

wordcloud 不能只是拿一个语料库然后神奇地生成一个 wordcloud.

wordcloud cannot just take a corpus and magically churn out a wordcloud.

你必须把它转换成一个TextDocumentMatrix,然后总结词频:

You have to do the hard work of converting it into a TextDocumentMatrix and then summing up the word frequencies:

# convert to TDM
tdm <- TermDocumentMatrix(carmenCorpus, control=list(stemming=True))

# calculate word frequencies
freqs = sort(rowSums(as.matrix(tdm)), decreasing=TRUE)

# plot wordcloud
wordcloud(names(freqs), freqs,
    max.words = 100,
    random.order = FALSE,
    # any other params you want to pass into wordcloud
    )

这篇关于使用 tm 包和 dtm/wordclouds 抛出新错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆