R中的情感分析

时间:2020-07-14 23:57:45

标签: r sentiment-analysis

我正在对数据框进行情感分析。数据帧的每一行都有一个“文本”变量,该变量由几个单词组成。我希望通过统计“ bing”词典中的正面和负面词来进行情感分析。但是,当我使用代码时:

sentiment <- tokens %>%
      inner_join(get_sentiments("bing")) %>% # pull out only sentimen words
      count(sentiment) %>% # count the # of positive & negative words
      spread(sentiment, n, fill = 0) %>% # made data wide rather than narrow
      mutate(sentiment = positive - negative) %>% # # of positive words - # of negative owrds

我得到了数据框中所有条目的计数。

有什么方法可以按数据帧的行进行计数。

例如,以下是数据框的行

user_id        text
1234           "Hello world"
1255           "Have a lot of fun"

当我使用前面的代码时,它将计算两个条目中文本变量的正负条目数。我希望它只计算每行的正负。

0 个答案:

没有答案