library(tm)
library(twitteR)
library(RCurl)
library(wordcloud)
## twitter API authorization (You will get all these keys from your twitter account )
consumer_key<-'please insert your twitter account consumer_key'
consumer_secret<-'please insert your twitter account consumer_secret'
access_token<-'please insert your twitter account access_token'
access_secret<-'please insert your twitter account access_secret'
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
tweet_data<-searchTwitter("Computer Engineering", n=500, lang="en")
##convert to vector
tweet_data_text<-sapply(tweet_data,function(x) x$getText())
##Create corpus from vector
data_corpus<-Corpus(VectorSource(tweet_data_text))
data_corpus
inspect(data_corpus[1])
#lowercase, remove numbers, cut out stopwards, remove puncuations, strip whitespace
data_clean<-tm_map(data_corpus, removePunctuation)
data_clean<-tm_map(data_clean,content_transformer(tolower))
data_clean<-tm_map(data_clean,removeWords, stopwords("english"))
data_clean<-tm_map(data_clean,removeNumbers)
data_clean<-tm_map(data_clean,stripWhitespace)
data_clean<-tm_map(data_clean,removeWords,c("vivo"))
wordcloud(data_clean,random.order = F)
df<-data.frame(text=unlist(sapply(data_clean,'[',"content")),stringsAsFactors = F)
write.csv(df,file = "tweets.csv")
library(twitteR)
library(RCurl)
library(wordcloud)
## twitter API authorization (You will get all these keys from your twitter account )
consumer_key<-'please insert your twitter account consumer_key'
consumer_secret<-'please insert your twitter account consumer_secret'
access_token<-'please insert your twitter account access_token'
access_secret<-'please insert your twitter account access_secret'
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
tweet_data<-searchTwitter("Computer Engineering", n=500, lang="en")
##convert to vector
tweet_data_text<-sapply(tweet_data,function(x) x$getText())
##Create corpus from vector
data_corpus<-Corpus(VectorSource(tweet_data_text))
data_corpus
inspect(data_corpus[1])
#lowercase, remove numbers, cut out stopwards, remove puncuations, strip whitespace
data_clean<-tm_map(data_corpus, removePunctuation)
data_clean<-tm_map(data_clean,content_transformer(tolower))
data_clean<-tm_map(data_clean,removeWords, stopwords("english"))
data_clean<-tm_map(data_clean,removeNumbers)
data_clean<-tm_map(data_clean,stripWhitespace)
data_clean<-tm_map(data_clean,removeWords,c("vivo"))
wordcloud(data_clean,random.order = F)
df<-data.frame(text=unlist(sapply(data_clean,'[',"content")),stringsAsFactors = F)
write.csv(df,file = "tweets.csv")
Output:-
No comments:
Post a Comment