【发布时间】:2020-12-01 11:23:30
【问题描述】:
我有以下问题:我有一个包含 3 列、行号、日期和一个单词的数据框。我正在尝试使用 https://www.tidytextmining.com/ 方法对 GitHub 提交 cmets 执行文本分析。我希望按季度计算我的总体情绪得分,而不是按我通过count(index = line %/% 10, sentiment) %>% 所做的 cmets 的数量。有没有一种简单的方法可以按季度计算我所有的“情绪分数”?
非常感谢您的任何建议。
single_word_with_date$date <- substr(single_word_with_date$date,1,nchar(single_word_with_date$date)-10)
single_word_with_date$date <- as.Date(single_word_with_date$date , format = "%Y-%m-%d")
comment_sentiments_with_date <- single_word_with_date %>%
inner_join(get_sentiments("bing")) %>%
count(index = date %/% month(date) , sentiment) %>%
spread(sentiment, n, fill = 0) %>%
mutate(sentiment = positive - negative)
这是数据框行是注释编号(例如,第 2 行注释中有几个单词),日期是日期时间,单词是字符串。
> head(single_word_with_date)
line date word
1 1 2011-11-16 love
2 2 2012-04-13 random
2.1 2 2012-04-13 question
2.8 2 2012-04-13 answered
2.14 2 2012-04-13 darwin
2.19 2 2012-04-13 purpose
【问题讨论】:
-
您可以使用
dput分享您的数据的代表性样本吗?阅读how to ask a good question 和how to give a reproducible example。 -
我在我的问题中添加了日期框架的前几行...抱歉
-
spread中的n是什么?您的数据中是否还有另一个名为n的列尚未显示?