r - R中的词云+语料库错误

标签 r twitter corpus

我想使用 Wordcloud 功能对 twitter 数据进行云计算。我已经安装了 twitter 包并使用了 api。之后我会做以下事情。

bigdata <- searchTwitter("#bigdata", n=20)

bigdata_list <- sapply(bigdata, function(x) x$getText())
bigdata_corpus <- Corpus(VectorSource(bigdata_list))
bigdata_corpus <- tm_map(bigdata_corpus, content_transformer(tolower), lazy=TRUE)
bigdata_corpus <- tm_map(bigdata_corpus, removePunctuation, lazy=TRUE)
bigdata_corpus <- tm_map(bigdata_corpus, 
                           function(x)removeWords(x,stopwords()), lazy=TRUE)
wordcloud(bigdata_corpus)

这会为 Wordcloud 命令生成错误消息:
Error in UseMethod("meta", x) : 
  no applicable method for 'meta' applied to an object of class "try-error"
In addition: Warning messages:
1: In mclapply(x$content[i], function(d) tm_reduce(d, x$lazy$maps)) :
  all scheduled cores encountered errors in user code
2: In mclapply(unname(content(x)), termFreq, control) :
  all scheduled cores encountered errors in user code

我尝试了不同的语料库命令,但似乎无法正确使用。
有任何想法吗?

最佳答案

你可以试试这个:

library("tm")
# Transform your corpus in a term document matrix
bigdata_tdm <- as.matrix(TermDocumentMatrix(bigdata_corpus))
# Get the frequency by words
bigdata_freq <- data.frame(Words = rownames(bigdata_tdm), Freq = rowSums(bigdata_tdm), stringsAsFactors = FALSE)
# sort
bigdata_freq <- bigdata_freq[order(bigdata_freq$Freq, decreasing = TRUE), ]
# keep the 50 most frequent words
bigdata_freq <- bigdata_freq[1:50, ]

# Draw the wordcloud
library("wordcloud")
wordcloud(words = bigdata_freq$Words, freq = bigdata_freq$Freq)

tm_0.6wordcloud_2.5两种方式都有效。

关于r - R中的词云+语料库错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27130608/

相关文章:

python - 通过python连接时如何更改默认的Mysql连接超时?

r - 将稀疏矩阵 (dgCMatrix) 转换为 realRatingMatrix

javascript - 使用推文按钮时与 dpi CSS 使用相关的控制台通知

javascript - 使用 javascript 动态设置推文按钮 'data-text' 内容,或者..?

html - 删除菜单和轮播之间的空格 Twitter bootstrap 2.2.2

r - 根据文本文件的内容对语料库进行子集化

python - 文本预处理

r - multidplyr 和 group_by () 和 filter()

r - 在 `arrange` 数据管道函数中将排序方向传递给 `dplyr`

将csv文件读入R,在每行的开头和结尾处包含括号