To study the sentiment of tweets about major US airlines during the 2016 Thanksgiving holiday travel period, the following code was used to capture the tweets. The data was then exported to .csv format to preserve the Twitter activity that occurred during the 2016 Thanksgiving holiday.
The Twitter authentication code is hidden for security purposes
#Download 2500 Tweets
num_tweets <- 2500
american <- searchTwitter('@AmericanAir', n = num_tweets)
delta <- searchTwitter('@Delta', n = num_tweets)
southwest <- searchTwitter('@SouthwestAir', n = num_tweets)
united <- searchTwitter('@united', n = num_tweets)
#Convert the list of Tweets to a Data Frame
american_df <- twListToDF(american) %>% mutate(airline = "American")
delta_df <- twListToDF(delta) %>% mutate(airline = "Delta")
southwest_df <- twListToDF(southwest) %>% mutate(airline = "Southwest")
united_df <- twListToDF(united) %>% mutate(airline = "United")
#bind the downloaded tweets to one dataframe
tweets_df <- rbind(american_df,delta_df,southwest_df,united_df) %>%
select(airline, tweet_created = `created`, text, name = `screenName`)
#To preserve the original set of twitter data
#tweets_df was exported to a .csv file & Date Changed as needed
write.csv(tweets_df, file = "Airline_Tweets_24NOV2016.csv",row.names=FALSE)