有谁知道为什么R中的aggregate包中的函数analyzeSentiment中的SentimentAnalysis参数不分组情绪分数?下面是一个简单的可复制示例:
> library(SentimentAnalysis)
> documents <- c("Wow, I really like the new light sabers!",
+ "That book was excellent.",
+ "R is a fantastic language.",
+ "The service in this restaurant was miserable.",
+ "This is neither positive or negative.",
+ "The waiter forget about my dessert -- what poor service!")
> Group=factor(c(1,1,2,2,3,3))
> Test_data=data.frame(documents=documents,Group=Group,stringsAsFactors = F)
> sentiment <- analyzeSentiment(x=Test_data$documents,aggregate=Test_data$Group)
> Test_data$SentimentQDAP=sentiment$SentimentQDAP
> Test_data
documents Group SentimentQDAP
1 Wow, I really like the new light sabers! 1 0.3333333
2 That book was excellent. 1 0.5000000
3 R is a fantastic language. 2 0.5000000
4 The service in this restaurant was miserable. 2 -0.3333333
5 This is neither positive or negative. 3 0.0000000
6 The waiter forget about my dessert -- what poor service! 3 -0.4000000这给了我以下几点:

关于函数analyzeSentiment的帮助说:“聚合:一个可以对文档进行分组的因素变量。这对于加入同一天的新闻或者移动同一作者的评论很有帮助”。
我的问题是,为什么每个小组的分数是不一样的?
发布于 2020-07-06 19:10:21
我检查了源代码的analyzeSentiment函数,看看aggregate参数会发生什么。
有趣的是,它没有在代码中执行任何操作的原因是,这个论点本质上是多余的--它根本没有被使用过!如果您遵循从初始analyzeSentiment函数开始的调用堆栈,则只会传递aggregate参数,直到它到达情感计算的主要中心-- analyzeSentiment.DocumentTermMatrix。这是计算结果的数据帧,然后返回的地方,传递给aggregate的值在代码中似乎没有出现。它已经通过了却从未使用过。
必须是它们从未添加到包中的特性,或者是前一个版本为了向后兼容性而遗留下来的工件。
https://stackoverflow.com/questions/62762130
复制相似问题