February 2018
Beginner to intermediate
258 pages
5h 47m
English
As explained earlier in this chapter, one thing you can do is to look for an annotated lexicon per sentiment and try to do some basic analysis there, thanks to the package tidytext.
First, we import a few libraries that would come handy and load our Twitter history:
library(plyr)library(dplyr)library(tidytext)library(ggplot2)df <- read.csv("./data/Tweets.csv", stringsAsFactors = F)text_df <- data_frame(tweet_id=df$tweet_id, tweet=df$text)
Now, we use the unnest_tokens function to bring the data into tidy format:
text_df <- text_df %>% unnest_tokens(word, tweet)
And remove the stop words:
data(stop_words)head(stop_words)text_df <- text_df %>% anti_join(stop_words)
Once this is done, we join it with, for instance, ...
Read now
Unlock full access