Dictionary based scoring

As described in the steps we outlined for our approach, let us use a sentiment dictionary to score our initially extracted tweets. We are going to leverage the sentimentr R package to learn the sentiments of the tweets we have collected.

Let us see how to score using the sentiment function from the sentimentr package: 

> library(sentimentr, quietly = TRUE)> sentiment.score <- sentiment(tweet.df$text)> head(sentiment.score)   element_id sentence_id word_count  sentiment1:          1           1          8  0.00000002:          2           1          8  0.35355343:          3           1          3  0.00000004:          3           2          4  0.00000005:          3           3          7  0.00000006:          4           1         14 -0.8418729

The sentiment function in sentimentr calculates a score between -1 and 1 for each of the tweets. In fact, if a tweet has multiple sentences, it ...

Get R Data Analysis Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.