forked from Kuldeep-Singh-Bithu/Sentiment_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentimentanalysisDataset.R
More file actions
28 lines (16 loc) · 1.2 KB
/
Copy pathSentimentanalysisDataset.R
File metadata and controls
28 lines (16 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# we can start processing the tweets to calculate the sentiment score.
scores = score.sentiment(airline, pos.words,neg.words , .progress='text')
#Create a variable in the data frame.
scores$airline = factor(rep(c("Delta", "JetBlue","United"), noof_tweets))
# Calculate positive, negative and neutral sentiments.
scores$positive <- as.numeric(scores$score >0)
scores$negative <- as.numeric(scores$score <0)
scores$neutral <- as.numeric(scores$score==0)
#Split the data frame into individual datasets for each airline.
delta_airline <- subset(scores, scores$airline=="Delta")
jetblue_airline <- subset(scores,scores$airline=="JetBlue")
united_airline <- subset(scores,scores$airline=="United")
#Create polarity variable for each data frame.
delta_airline$polarity <- ifelse(delta_airline$score >0,"positive",ifelse(delta_airline$score < 0,"negative",ifelse(delta_airline$score==0,"Neutral",0)))
jetblue_airline$polarity <- ifelse(jetblue_airline$score >0,"positive",ifelse(jetblue_airline$score < 0,"negative",ifelse(jetblue_airline$score==0,"Neutral",0)))
united_airline$polarity <- ifelse(united_airline$score >0,"positive",ifelse(united_airline$score < 0,"negative",ifelse(united_airline$score==0,"Neutral",0)))