我正在研究古腾堡项目中的弗洛伊德书籍的文本挖掘。当我尝试进行情绪分析时,使用以下代码:
library(dplyr)
library(tidytext)
library(gutenbergr)
freud_books <- gutenberg_download(c(14969, 15489, 34300, 35875, 35877, 38219, 41214), meta_fields = "title")
tidy_books <- freud_books %>%
unnest_tokens(word, text)
f_sentiment <- tidy_books %>%
inner_join(get_sentiments("bing"), by = "word") %>%
count(title, index = line %/% 80, sentiment) %>%
spread(sentiment, n, fill = 0) %>%
mutate(sentiment = positive - negative)我知道错误:
Mutate_impl中的错误(.data,dots):求值错误:二进制运算符的非数值参数.
我可以看到问题在最后一个块中,在计数函数中。对此有什么帮助吗?
发布于 2018-05-03 21:07:03
在使用line函数之后,应该将inner_join转换成数据,因为它不是数据的列,所以如果需要,就必须自己创建它
注意mutate(line = row_number())部件,如果需要另一种分配行号的方法,可以修改它,然后可以在count中使用index = line %/% 80
试试这个:
library(dplyr)
library(tidytext)
library(gutenbergr)
freud_books <- gutenberg_download(c(14969, 15489, 34300, 35875, 35877, 38219, 41214),
meta_fields = "title")
tidy_books <- freud_books %>%
unnest_tokens(word, text)
f_sentiment <- tidy_books %>%
inner_join(get_sentiments("bing"), by = "word") %>%
mutate(line = row_number()) %>%
count(title, index = line %/% 80, sentiment) %>%
spread(sentiment, n, fill = 0) %>%
mutate(sentiment = positive - negative)https://stackoverflow.com/questions/50163659
复制相似问题