Guest User

Untitled

a guest
Jun 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #calculate the sentiment score
  2. sentiment_tweets<-sentiment(tweets.df$text)
  3.  
  4.  
  5. #adding sentiment score to df
  6. tweets.df<-tweets.df%>%mutate(sentiment=sentiment_tweets$sentiment)
  7. View(tweets.df)
  8.  
  9.  
  10. #get the positive sentiment score
  11. positive_tweets<-head(arrange(unique(tweets.df[,c(1,17)]),desc(sentiment)),30)
  12. positive_tweets
  13. write.table(positive_tweets$text,file='E:/Program Files/RStudio/New folder/pos_tweets.txt',sep='n')
  14.  
  15.  
  16. #get the negative sentiment score
  17. negative_tweets<-head(arrange(unique(tweets.df[,c(1,17)]),sentiment),30)
  18. negative_tweets
  19. write.table(positive_tweets$text,file='E:/Program Files/RStudio/New folder/neg_tweets.txt',sep='n')
  20.  
  21.  
  22. #get the document
  23. mycorpus2<-Corpus(DirSource(directory='E:/Program Files/RStudio/New folder'))
  24. summary(mycorpus2)
  25.  
  26.  
  27. #clean the document
  28. mycorpus2<-tm_map(mycorpus2,tolower)
  29. mycorpus2<-tm_map(mycorpus2,removePunctuation)
  30. mycorpus2<-tm_map(mycorpus2,removeWords,stopwords())
  31. mycorpus2<-tm_map(mycorpus2,stripWhitespace)
  32. mycorpus2<-tm_map(mycorpus2,stemDocument)
  33.  
  34.  
  35.  
  36. #convert corpus(class) into tdm
  37. mycorpus2_tdm<-TermDocumentMatrix(mycorpus2)
  38.  
  39.  
  40. #convert tdm into matrix
  41. mycorpus2_matrix<-as.matrix(mycorpus2_tdm)
  42.  
  43. #name the columns
  44. colnames(mycorpus2_matrix)<-c('negative','positive')
  45. head(mycorpus2_matrix)
  46.  
  47.  
  48. #graphing the key words
  49. comparison.cloud(mycorpus2_matrix,max.words=100,random.order=F)
Add Comment
Please, Sign In to add comment