Blogpost_5.Text as Data

Mani kanta Gogula
4/15/2022
# A tibble: 6 x 3
     id label tweet                                                   
  <dbl> <dbl> <chr>                                                   
1     1     0 "@user when a father is dysfunctional and is so selfish~
2     2     0 "@user @user thanks for #lyft credit i can't use cause ~
3     3     0 "bihday your majesty"                                   
4     4     0 "#model   i love u take with u all the time in urð\u009~
5     5     0 "factsguide: society now    #motivation"                
6     6     0 "[2/2] huge fan fare and big talking before they leave.~
colnames(TwitterHate)
[1] "id"    "label" "tweet"
tweet_<-select(TwitterHate,tweet)
tweet_
# A tibble: 31,962 x 1
   tweet                                                              
   <chr>                                                              
 1 "@user when a father is dysfunctional and is so selfish he drags h~
 2 "@user @user thanks for #lyft credit i can't use cause they don't ~
 3 "bihday your majesty"                                              
 4 "#model   i love u take with u all the time in urð\u009f\u0093±!!!~
 5 "factsguide: society now    #motivation"                           
 6 "[2/2] huge fan fare and big talking before they leave. chaos and ~
 7 "@user camping tomorrow @user @user @user @user @user @user @user ~
 8 "the next school year is the year for exams.ð\u009f\u0098¯ can't t~
 9 "we won!!! love the land!!! #allin #cavs #champions #cleveland #cl~
10 "@user @user welcome here !  i'm   it's so #gr8 !"                 
# ... with 31,952 more rows
corpus <-iconv(TwitterHate$tweet)
corpus<-Corpus(VectorSource(corpus))
inspect(corpus[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] @user when a father is dysfunctional and is so selfish he drags his kids into his dysfunction.   #run                     
[2] @user @user thanks for #lyft credit i can't use cause they don't offer wheelchair vans in pdx.    #disapointed #getthanked
[3] bihday your majesty                                                                                                       
[4] #model   i love u take with u all the time in ur📱!!! ðŸÂ\230Â\231ðŸÂ\230ŽðŸ‘„👅💦💦💦      
[5] factsguide: society now    #motivation                                                                                    
corpus <- tm_map(corpus, tolower)
inspect(corpus[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] @user when a father is dysfunctional and is so selfish he drags his kids into his dysfunction.   #run                     
[2] @user @user thanks for #lyft credit i can't use cause they don't offer wheelchair vans in pdx.    #disapointed #getthanked
[3] bihday your majesty                                                                                                       
[4] #model   i love u take with u all the time in urã°âÿâ“â±!!! ã°âÿâ\230â\231ã°âÿâ\230âžã°âÿâ‘â„ã°âÿâ‘â…ã°âÿâ’â¦ã°âÿâ’â¦ã°âÿâ’⦠     
[5] factsguide: society now    #motivation                                                                                    
corpus <- tm_map(corpus, removePunctuation)
inspect(corpus[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] user when a father is dysfunctional and is so selfish he drags his kids into his dysfunction   run                
[2] user user thanks for lyft credit i cant use cause they dont offer wheelchair vans in pdx    disapointed getthanked
[3] bihday your majesty                                                                                               
[4] model   i love u take with u all the time in urã°âÿâ“â± ã°âÿâ\230â\231ã°âÿâ\230âžã°âÿâ‘â„ã°âÿâ‘â…ã°âÿâ’â¦ã°âÿâ’â¦ã°âÿâ’⦠ 
[5] factsguide society now    motivation                                                                              
corpus <- tm_map(corpus, removeNumbers)
inspect(corpus[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] user when a father is dysfunctional and is so selfish he drags his kids into his dysfunction   run                
[2] user user thanks for lyft credit i cant use cause they dont offer wheelchair vans in pdx    disapointed getthanked
[3] bihday your majesty                                                                                               
[4] model   i love u take with u all the time in urã°âÿâ“â± ã°âÿâ\230â\231ã°âÿâ\230âžã°âÿâ‘â„ã°âÿâ‘â…ã°âÿâ’â¦ã°âÿâ’â¦ã°âÿâ’⦠ 
[5] factsguide society now    motivation                                                                              
cleanset <- tm_map(corpus, removeWords, stopwords('english'))
inspect(cleanset[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] user   father  dysfunctional    selfish  drags  kids   dysfunction   run                                
[2] user user thanks  lyft credit  cant use cause  dont offer wheelchair vans  pdx    disapointed getthanked
[3] bihday  majesty                                                                                         
[4] model    love u take  u   time  urã°âÿâ“â± ã°âÿâ\230â\231ã°âÿâ\230âžã°âÿâ‘â„ã°âÿâ‘â…ã°âÿâ’â¦ã°âÿâ’â¦ã°âÿâ’⦠    
[5] factsguide society now    motivation                                                                    
removeURL <- function(x) gsub('http[[:alnum:]]*', '', x)
cleanset <- tm_map(cleanset, content_transformer(removeURL))
inspect(cleanset[1:5])
<<SimpleCorpus>>
Metadata:  corpus specific: 1, document level (indexed): 0
Content:  documents: 5

[1] user   father  dysfunctional    selfish  drags  kids   dysfunction   run                                
[2] user user thanks  lyft credit  cant use cause  dont offer wheelchair vans  pdx    disapointed getthanked
[3] bihday  majesty                                                                                         
[4] model    love u take  u   time  urã°âÿâ“â± ã°âÿâ\230â\231ã°âÿâ\230âžã°âÿâ‘â„ã°âÿâ‘â…ã°âÿâ’â¦ã°âÿâ’â¦ã°âÿâ’⦠    
[5] factsguide society now    motivation                                                                    
library(wordcloud)
set.seed(100)
wordcloud(words = TwitterHate$tweet, random.order=TRUE)