我正在使用维达情绪分析在tweets上的一个项目,我的3000推特。当我只为一条推特运行情绪时,一切都很好。这给了我所有的分数,但当我运行循环命令对所有的tweet,我只得到最终的结果,作为Vader的综合得分。我有兴趣得到最后的结果,作为第一个给出所有分数的结果。任何帮助都将不胜感激。
样本数据:
dput(data_sample$text)
c("Need DoorDash or Uber method asap cause I be starving",
"I’m such a real ahh niqq cuz I be having myself weak asl",
"This shii made me laugh so fuccin hard bro",
"Kevin Hart and Will Ferrell made a Gem in Get hard fr",
"@_big_emmy @NigerianAmazon Chill", "Ts so bomedy ",
"So is that ass Gotdam",
"This wild", "Idc them late night DoorDash’s be goin crazy",
"Video of the week")代码:
get_vader(data_sample$text[1])我需要以下循环中所有10条tweet的结果:
word_scores compound pos
"{0, 0, 0, 0, 0, 0, 0, 0, 0, -1.8}" "-0.421" "0"
neu neg but_count
"0.763" "0.237" "0" 不是这样的:
for (i in 1:length(data_sample$text)){
Loop_Error <- F
tryCatch({
get_vader(data_sample$text[i]) %>%
as.numeric(unlist(.)) %>%
.[length(.)-4] ->data_sample$score_vader[i]
}, error = function(e){
Loop_Error <<- T})
if (Loop_Error){
data_sample$score_vader[i] <- "Error"
}
}
vader_data
data_sample$score_vader
1 -0.421
2 -0.440
3 0.444
4 -0.103
5 0.000
6 0.000
7 -0.581
8 0.000
9 -0.340
10 0.000发布于 2022-07-20 05:10:48
我有这样的想法,以获得data_sample的所有get_vader()输出,但您需要修改代码才能使用vader_df()
allvals <- NULL
for (i in 1:length(data_sample)){
outs <- vader_df(data_sample[i])
allvals <- rbind(allvals,outs)
}https://stackoverflow.com/questions/73046093
复制相似问题