维德在r中的情感分析



我在一个有3000条推文的项目中使用了维德情感分析。当我只运行一条tweet的情绪时,一切都很好。这将为我提供该推文的所有分数,但是当我对所有推文运行loop命令时,我只会得到最终结果,即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

我有这个想法,以获得get_vader()给出的data_sample的所有输出,但您需要修改您的代码来使用vader_df():

allvals <- NULL
for (i in 1:length(data_sample)){
outs <-  vader_df(data_sample[i])
allvals <- rbind(allvals,outs)
}

最新更新