Twittermining: 1 Twitter Text Mining - Required Libraries
Twittermining: 1 Twitter Text Mining - Required Libraries
Twittermining: 1 Twitter Text Mining - Required Libraries
In [2]: library(twitteR)
library(ROAuth)
library(RCurl)
library(httr)
library(stringr)
library(plyr)
library(dplyr)
library(tm)
#library(ggmap)
#library(wordcloud)
Enter your key and token from your twitter developer page
In [ ]: key=" "
secret=" "
In [ ]: library("stringr")
library("plyr")
1
# Parameters
# tweettext: vector of text to score
# pos: vector of words of postive sentiment
# neg: vector of words of negative sentiment
# .progress: passed to laply() 4 control of progress bar
# final score
score = sum(pos.matches) - sum(neg.matches)
return(score)},
pos, neg, .progress=.progress)
2
# data frame with scores for each sentence
sentiment.df = data.frame(text=tweettext, score=scores)
return(sentiment.df)
}
In [ ]: pos = readLines("positive_words.txt")
neg = readLines("negative_words.txt")
3
7 Extracting further elements (besides text) for the export csv
In [ ]: data=as.data.frame(cbind(ttext=tweettext,
date=tweetdate,
isretweet=isretweet,
retweetcount=retweetcount,
favoritecount=favoritecount,
score = scores$score,
product = "Samsung Galaxy",
city = "Seattle", country = "USA"))