Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #calculate the sentiment score
- sentiment_tweets<-sentiment(tweets.df$text)
- #adding sentiment score to df
- tweets.df<-tweets.df%>%mutate(sentiment=sentiment_tweets$sentiment)
- View(tweets.df)
- #get the positive sentiment score
- positive_tweets<-head(arrange(unique(tweets.df[,c(1,17)]),desc(sentiment)),30)
- positive_tweets
- write.table(positive_tweets$text,file='E:/Program Files/RStudio/New folder/pos_tweets.txt',sep='n')
- #get the negative sentiment score
- negative_tweets<-head(arrange(unique(tweets.df[,c(1,17)]),sentiment),30)
- negative_tweets
- write.table(positive_tweets$text,file='E:/Program Files/RStudio/New folder/neg_tweets.txt',sep='n')
- #get the document
- mycorpus2<-Corpus(DirSource(directory='E:/Program Files/RStudio/New folder'))
- summary(mycorpus2)
- #clean the document
- mycorpus2<-tm_map(mycorpus2,tolower)
- mycorpus2<-tm_map(mycorpus2,removePunctuation)
- mycorpus2<-tm_map(mycorpus2,removeWords,stopwords())
- mycorpus2<-tm_map(mycorpus2,stripWhitespace)
- mycorpus2<-tm_map(mycorpus2,stemDocument)
- #convert corpus(class) into tdm
- mycorpus2_tdm<-TermDocumentMatrix(mycorpus2)
- #convert tdm into matrix
- mycorpus2_matrix<-as.matrix(mycorpus2_tdm)
- #name the columns
- colnames(mycorpus2_matrix)<-c('negative','positive')
- head(mycorpus2_matrix)
- #graphing the key words
- comparison.cloud(mycorpus2_matrix,max.words=100,random.order=F)
Add Comment
Please, Sign In to add comment