6.4 Sentiment analysis

Now that we have assembled the data set with tweets pertaining to the 9 airlines, we are ready to do sentiment analysis. We will use get_nrc_sentiment() from syuzhet package. The input to this function is a character vector. Therefore, we will simply pull() this vector out from airlines_df.

Depending on the number of tweets this code will take a few minutes to execute so please be patient.

airlines_sent <- airlines_df %>% 
  pull(text) %>%  # This returns a character vector 
  get_nrc_sentiment()

Take a look at the sentiment data using head(). For my sample, the results are shown in Table 6.2,

Table 6.2: Airlines Sentiment
anger anticipation disgust fear joy sadness surprise trust negative positive
0 2 0 0 0 0 0 0 0 0
1 1 0 0 1 0 1 1 1 1
0 1 0 0 1 0 0 1 0 1
0 0 0 0 0 0 0 0 0 0
0 2 0 2 0 1 0 1 2 1
1 2 1 0 1 1 1 2 1 2
0 1 0 0 1 0 0 1 0 1
0 1 0 0 0 0 0 0 0 0