有人知道为什么R中SentimentAnalysis包中的函数aggregate
中的analyzeSentiment
自变量没有对情感分数进行分组吗?这是一个简单的可复制示例:
> 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
哪些给了我以下内容:
函数analysisSentiment上的帮助说:“ 汇总:一个可以对文档进行分组的因子变量。当加入例如同一天的新闻或移动同一作者的评论时,这很有用。” < / p>
我的问题是,为什么每个小组的分数都不一样?
答案 0 :(得分:1)
我检查了analyzeSentiment
函数的source code,以查看该aggregate
自变量会发生什么情况。
有趣的是,它在您的代码中没有执行任何操作的原因是因为该参数本质上是多余的-它从未使用过!如果您从最初的analyzeSentiment
函数开始遵循调用堆栈,则aggregate
参数会被传递,直到到达情感计算的主要中心analyzeSentiment.DocumentTermMatrix
。这是计算结果数据帧然后返回的地方,传递给aggregate
的值似乎在代码中的任何地方都没有出现。它已传入并且从未使用过。
必须是它们从未添加到软件包中的功能,或者是为了向后兼容而保留在先前版本中的构件。