This is a Notebook for Twitter entiment Analysis on CVS Health and CVS Aetna merger.

#  Install Requried Packages
#install.packages("SnowballC")
#install.packages("tm")
#install.packages("twitteR")
#install.packages("syuzhet")

# Load Requried Packages
library("SnowballC")
library("tm")
library("twitteR")
library("syuzhet")
library("wordcloud")

Setting up Twitter OAuth

consumer_key <-  'elVqMFVWgCUQBEDOR7vsfFsI7'
consumer_secret <- '5LizGPvZIZoHYojLhYFrfFXm2KjjIeCPvFwNiIhcOfdnAGzrKO'
access_token <- '380945634-TLTP7C0llQjRu4S5jPJvHKadGJnQ0V8m9DPrAhur'
access_secret <- 'XX26mpkPytRrlKi38tQDdE36RgE9s04KA8Q2FEsPYg14B'
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
## [1] "Using direct authentication"
tweets <- userTimeline("CVSHealth", n=200)

n.tweet <- length(tweets)
#save text
tweets_text <- sapply(tweets, function(x) x$getText())

#create corpus - Constructs a text document collection (corpus).
tweets_text_corpus <- Corpus(VectorSource(tweets_text))
tweets_text_corpus <- tm_map(tweets_text_corpus, function(x) iconv(enc2utf8(x), sub = "byte"))
tweets_text_corpus <- tm_map(tweets_text_corpus, content_transformer(tolower)) 
tweets_text_corpus <- tm_map(tweets_text_corpus, removePunctuation)
tweets_text_corpus <- tm_map(tweets_text_corpus, function(x)removeWords(x,stopwords()))
wordcloud(as.character(tweets_text_corpus))

Searching Twitter

num_tweets <- 200
r_stats <- searchTwitter(c("#CVSAetna","#CVSHealth", "#Aetna"), n=num_tweets) #, since = "2016-01-01", until = "2018-06-09")
## Warning in if (nchar(searchString) > 1000) {: the condition has length > 1
## and only the first element will be used
## Warning in doRppAPICall("search/tweets", n, params = params,
## retryOnRateLimit = retryOnRateLimit, : 200 tweets were requested but the
## API can only return 5
head(r_stats)
## [[1]]
## [1] "casemanagers: Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/HJgj1Pf6W8"
## 
## [[2]]
## [1] "MedicalHome: Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/ZoE4jXTwcO"
## 
## [[3]]
## [1] "brucejapsen: RT @UrgentCareNews: More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via @forbeshealth #b…"
## 
## [[4]]
## [1] "UrgentCareNews: More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via… https://t.co/ZKzGI6keDs"
## 
## [[5]]
## [1] "sonodoc99: #CVSAetna Too Big To Regulate https://t.co/hRyD2kMdpE @MSSNYRothberg https://t.co/tUqy2EYhGP"
tweets.df <- twListToDF(tweets) 
 
head(tweets.df)
##                                                                                                                                               text
## 1          .@CVSHealth President &amp; CEO Larry Merlo to participate in @aspenideas on 6/21 to discuss transformation in… https://t.co/o8tnG3HhUz
## 2 .@CVSHealth has donated $10K to @CarryTheLoad where funds are distributed to nonprofits that support #veterans &amp; th… https://t.co/v2EoUdYJBL
## 3 Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… https://t.co/CiefidY8ff
## 4      We held 450 #ProjectHealth free wellness events over 4 months in 10 multicultural communities w/ a large number of… https://t.co/7H289kYeBD
## 5                              .@CVSHealth is wishing all dads a Happy Father’s Day! Thank you for all you do. #FathersDay https://t.co/06LcHWfGVw
## 6          .@CVSHealth expands its safe medication disposal program to select @CVSPharmacy locations in VA to help combat… https://t.co/NKtrhCeUdo
##   favorited favoriteCount replyToSN             created truncated
## 1     FALSE             2      <NA> 2018-06-18 19:01:01      TRUE
## 2     FALSE             5      <NA> 2018-06-18 18:05:07      TRUE
## 3     FALSE             1      <NA> 2018-06-18 15:40:08      TRUE
## 4     FALSE             3      <NA> 2018-06-18 13:05:12      TRUE
## 5     FALSE            24      <NA> 2018-06-17 13:10:06     FALSE
## 6     FALSE             4      <NA> 2018-06-15 16:01:19      TRUE
##   replyToSID                  id replyToUID
## 1       <NA> 1008786677823926272       <NA>
## 2       <NA> 1008772612464562178       <NA>
## 3       <NA> 1008736126117572608       <NA>
## 4       <NA> 1008697134831554562       <NA>
## 5       <NA> 1008335980212965376       <NA>
## 6       <NA> 1007654292394782721       <NA>
##                                                            statusSource
## 1 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 2 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 3 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 4 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 5 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 6 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
##   screenName retweetCount isRetweet retweeted longitude latitude
## 1  CVSHealth            1     FALSE     FALSE        NA       NA
## 2  CVSHealth            0     FALSE     FALSE        NA       NA
## 3  CVSHealth            1     FALSE     FALSE        NA       NA
## 4  CVSHealth            4     FALSE     FALSE        NA       NA
## 5  CVSHealth            8     FALSE     FALSE        NA       NA
## 6  CVSHealth            1     FALSE     FALSE        NA       NA
head(tweets.df$text)
## [1] ".@CVSHealth President &amp; CEO Larry Merlo to participate in @aspenideas on 6/21 to discuss transformation in… https://t.co/o8tnG3HhUz"         
## [2] ".@CVSHealth has donated $10K to @CarryTheLoad where funds are distributed to nonprofits that support #veterans &amp; th… https://t.co/v2EoUdYJBL"
## [3] "Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… https://t.co/CiefidY8ff"
## [4] "We held 450 #ProjectHealth free wellness events over 4 months in 10 multicultural communities w/ a large number of… https://t.co/7H289kYeBD"     
## [5] ".@CVSHealth is wishing all dads a Happy Father’s Day! Thank you for all you do. #FathersDay https://t.co/06LcHWfGVw"                             
## [6] ".@CVSHealth expands its safe medication disposal program to select @CVSPharmacy locations in VA to help combat… https://t.co/NKtrhCeUdo"

We checked the Twitter Sentiments to see how that is affecting the deal : http://rpubs.com/SShivakumar/TwitterSentimentAnalysis

r_stats.df <- twListToDF(r_stats) 
 
head(r_stats.df)
##                                                                                                                                           text
## 1                             Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/HJgj1Pf6W8
## 2                             Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/ZoE4jXTwcO
## 3 RT @UrgentCareNews: More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via @forbeshealth #b…
## 4              More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via… https://t.co/ZKzGI6keDs
## 5                                                 #CVSAetna Too Big To Regulate https://t.co/hRyD2kMdpE @MSSNYRothberg https://t.co/tUqy2EYhGP
##   favorited favoriteCount replyToSN             created truncated
## 1     FALSE             0        NA 2018-06-14 21:50:11     FALSE
## 2     FALSE             0        NA 2018-06-14 21:50:11     FALSE
## 3     FALSE             0        NA 2018-06-14 20:39:26     FALSE
## 4     FALSE             1        NA 2018-06-14 18:20:05      TRUE
## 5     FALSE             0        NA 2018-06-14 14:07:23     FALSE
##   replyToSID                  id replyToUID
## 1         NA 1007379699453059074         NA
## 2         NA 1007379699352424448         NA
## 3         NA 1007361894951219200         NA
## 4         NA 1007326826748891136         NA
## 5         NA 1007263233462472704         NA
##                                                            statusSource
## 1       <a href="http://www.hootsuite.com" rel="nofollow">Hootsuite</a>
## 2       <a href="http://www.hootsuite.com" rel="nofollow">Hootsuite</a>
## 3    <a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>
## 4 <a href="https://www.hootsuite.com" rel="nofollow">Hootsuite Inc.</a>
## 5    <a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>
##       screenName retweetCount isRetweet retweeted longitude latitude
## 1   casemanagers            0     FALSE     FALSE        NA       NA
## 2    MedicalHome            0     FALSE     FALSE        NA       NA
## 3    brucejapsen            1      TRUE     FALSE        NA       NA
## 4 UrgentCareNews            1     FALSE     FALSE        NA       NA
## 5      sonodoc99            0     FALSE     FALSE        NA       NA
head(r_stats.df$text)
## [1] "Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/HJgj1Pf6W8"                            
## [2] "Synergies from Non-Traditional #CVSAetna Merger #Healthcare Trends 2018 Podcast 5:25 min https://t.co/ZoE4jXTwcO"                            
## [3] "RT @UrgentCareNews: More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via @forbeshealth #b…"
## [4] "More good news for #CVSAetna with AMA quiet on deal. @brucejapsen reports: https://t.co/euJid1v14M via… https://t.co/ZKzGI6keDs"             
## [5] "#CVSAetna Too Big To Regulate https://t.co/hRyD2kMdpE @MSSNYRothberg https://t.co/tUqy2EYhGP"
tweets.df2 <- gsub("http.*","",tweets.df$text)
 
tweets.df2 <- gsub("https.*","",tweets.df2)
 
tweets.df2 <- gsub("#.*","",tweets.df2)
 
tweets.df2 <- gsub("@.*","",tweets.df2)
r_stats.df2 <- gsub("http.*","",r_stats.df$text)
 
r_stats.df2 <- gsub("https.*","",r_stats.df2)
 
r_stats.df2 <- gsub("#.*","",r_stats.df2)
 
r_stats.df2 <- gsub("@.*","",r_stats.df2)

head(r_stats.df2)
## [1] "Synergies from Non-Traditional " "Synergies from Non-Traditional "
## [3] "RT "                             "More good news for "            
## [5] ""
word.df <- as.vector(tweets.df2)
 
emotion.df <- get_nrc_sentiment(word.df)
 
emotion.df2 <- cbind(tweets.df2, emotion.df) 
 
head(emotion.df2)
##                                                                                                                  tweets.df2
## 1                                                                                                                         .
## 2                                                                                                                         .
## 3 Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… 
## 4                                                                                                              We held 450 
## 5                                                                                                                         .
## 6                                                                                                                         .
##   anger anticipation disgust fear joy sadness surprise trust negative
## 1     0            0       0    0   0       0        0     0        0
## 2     0            0       0    0   0       0        0     0        0
## 3     0            0       0    0   0       0        0     1        0
## 4     0            0       0    0   0       0        0     0        0
## 5     0            0       0    0   0       0        0     0        0
## 6     0            0       0    0   0       0        0     0        0
##   positive
## 1        0
## 2        0
## 3        3
## 4        0
## 5        0
## 6        0
word_rstats.df <- as.vector(r_stats.df2)
 
emotion_rstats.df <- get_nrc_sentiment(word_rstats.df)
 
emotion_rstats.df2 <- cbind(r_stats.df2, emotion_rstats.df) 
 
head(emotion_rstats.df2)
##                       r_stats.df2 anger anticipation disgust fear joy
## 1 Synergies from Non-Traditional      0            0       0    0   0
## 2 Synergies from Non-Traditional      0            0       0    0   0
## 3                             RT      0            0       0    0   0
## 4             More good news for      0            1       0    0   1
## 5                                     0            0       0    0   0
##   sadness surprise trust negative positive
## 1       0        0     0        0        1
## 2       0        0     0        0        1
## 3       0        0     0        0        0
## 4       0        1     1        0        1
## 5       0        0     0        0        0
sent.value <- get_sentiment(word.df)
 
most.positive <- word.df[sent.value == max(sent.value)]
 
most.positive
## [1] "New collaboration w/ Job Corps committed to enhance workforce development opportunities for aspiring pharmacy techn… "
sent.value_rstats <- get_sentiment(word_rstats.df)
 
most.positive_rstats <- word.df[sent.value_rstats == max(sent.value_rstats)]
 
most.positive_rstats
##  [1] "We held 450 "                                                                                                                 
##  [2] "."                                                                                                                            
##  [3] "Read how "                                                                                                                    
##  [4] "."                                                                                                                            
##  [5] ""                                                                                                                             
##  [6] "Addressing Rising Health Care Costs "                                                                                         
##  [7] "."                                                                                                                            
##  [8] "Growing Communities Through Supplier Diversity "                                                                              
##  [9] "At "                                                                                                                          
## [10] "Read more about "                                                                                                             
## [11] "Health Care Consumerism: Increasing Transparency to Aid Decision-Making "                                                     
## [12] "Providing Patient-Focused Infusion Support for Better Health Outcomes "                                                       
## [13] "Helping Veterans Find Meaningful Careers "                                                                                    
## [14] "."                                                                                                                            
## [15] "."                                                                                                                            
## [16] "You can help support efforts in lung cancer research, awareness and prevention by donating to "                               
## [17] "."                                                                                                                            
## [18] "Since the "                                                                                                                   
## [19] "We believe patients should have more transparency into their drug costs, which is what we're working towards w/the… "         
## [20] ""                                                                                                                             
## [21] "For the second year in a row, "                                                                                               
## [22] "Putting Patients at the Center of Health Care Transformation "                                                                
## [23] "."                                                                                                                            
## [24] "Policy solutions that lower drug prices for consumers &amp; reduce OOP costs are in alignment w/ "                            
## [25] "Since 2015, "                                                                                                                 
## [26] "Increasing transparency into patients’ drug benefits at POP &amp; at the pharmacy helps prescribers + patients better u… "    
## [27] "Thomas Moriarty, Chief Policy &amp; External Affairs Officer for "                                                            
## [28] "Moriarty: "                                                                                                                   
## [29] "Thanks to the "                                                                                                               
## [30] "Evolving the Population Health Management Paradigm "                                                                          
## [31] "CMO Dr. Brennan discusses our vision for "                                                                                    
## [32] "Girls have the right to pursue healthy lifestyles &amp; access essential healthcare services. Supporting &amp; promoting gi… "
## [33] "Promoting Mental Health Awareness with Girls Inc. "                                                                           
## [34] "Solutions to Help Make Health Care More Affordable "                                                                          
## [35] "."                                                                                                                            
## [36] "."                                                                                                                            
## [37] "Q1 Earnings: The Q1 results underscore the early success we are achieving against our four-point plan to return to… "
most.negative <- word.df[sent.value <= min(sent.value)] 

most.negative 
## [1] "News | CVS Health Expands Safe Drug Disposal at CVS Pharmacy Locations in Virginia to Help Combat Opioid Abuse "
## [2] "Safely disposing of unwanted or unused medication is one element of our company-wide approach to address the… "
most.negative_rstats <- word.df[sent.value_rstats <= min(sent.value_rstats)] 

most.negative_rstats 
##   [1] "."                                                                                                                            
##   [2] "."                                                                                                                            
##   [3] "Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… "    
##   [4] "."                                                                                                                            
##   [5] "."                                                                                                                            
##   [6] "Thank you AG "                                                                                                                
##   [7] "We’ve implemented numerous programs &amp; initiatives aimed at diversity in the workplace, like a supplier diversity pr… "    
##   [8] "CVS Health Shows Support for First Responders "                                                                               
##   [9] "Thank you Senator "                                                                                                           
##  [10] "News | CVS Health Expands Safe Drug Disposal at CVS Pharmacy Locations in Virginia to Help Combat Opioid Abuse "              
##  [11] "Annual OOP health care costs can be significant for many patients. "                                                          
##  [12] "Congrats to "                                                                                                                 
##  [13] "."                                                                                                                            
##  [14] "Since 2016, "                                                                                                                 
##  [15] "Health Care Consumerism: Connecting Patients to More Affordable Care "                                                        
##  [16] "The average list price of brand medicines has increased by 58% over the past 5 years. Read how "                              
##  [17] "Carry The Load: Honoring Our Nation’s Heroes "                                                                                
##  [18] "."                                                                                                                            
##  [19] "DYK: "                                                                                                                        
##  [20] "Learn more about our retail-based pilot program which focuses on three target groups; patients w/5 common chronic d… "        
##  [21] ""                                                                                                                             
##  [22] "."                                                                                                                            
##  [23] "."                                                                                                                            
##  [24] "Hear from Hailee, whose two year old daughter requires daily IV feeding support &amp; see how Coram provides one-on-one… "    
##  [25] "Thank you "                                                                                                                   
##  [26] "Partnering to Meet Veterans’ Health Needs "                                                                                   
##  [27] "News | CVS Health Applauds New Law Expanding Veterans' Access to High-Quality, Cost-Effective Walk-In Care Providers "        
##  [28] "How much do you think advancements in health care technology will change the care you receive over the next decade?"          
##  [29] ""                                                                                                                             
##  [30] "News | CVS Health Announces Management Team for Combined Company Following Close of Aetna Acquisition Transaction "           
##  [31] "."                                                                                                                            
##  [32] "6/8 is the last day for diverse business owners to apply for the "                                                            
##  [33] "We believe the health of our planet is inextricably linked to the health of all people. Learn how we’re reducing ou… "        
##  [34] "."                                                                                                                            
##  [35] "."                                                                                                                            
##  [36] ""                                                                                                                             
##  [37] ""                                                                                                                             
##  [38] "To learn more about "                                                                                                         
##  [39] ""                                                                                                                             
##  [40] "."                                                                                                                            
##  [41] "For more info on how we’re working to ensure patients have access to affordable health care, visit the "                      
##  [42] "Learn how "                                                                                                                   
##  [43] "On this "                                                                                                                     
##  [44] "WATCH: Troyen A. Brennan, M.D., Executive VP &amp; Chief Medical Officer for "                                                
##  [45] ""                                                                                                                             
##  [46] "."                                                                                                                            
##  [47] "As one of the largest drug purchasers in the U.S. health care system, "                                                       
##  [48] "The 28 new medication disposal units installed at "                                                                           
##  [49] "Stay informed about the most talked-about topics in "                                                                         
##  [50] "."                                                                                                                            
##  [51] "We’re excited to celebrate our first anniversary of expanded access to care for "                                             
##  [52] "."                                                                                                                            
##  [53] ""                                                                                                                             
##  [54] "On this "                                                                                                                     
##  [55] "Today is the last day to donate to "                                                                                          
##  [56] "In February 2018, the "                                                                                                       
##  [57] "To find one of the 25 "                                                                                                       
##  [58] "CMO Dr. Brennan outlines how the combination of data-driven insights and retail health care can support the primary… "        
##  [59] "As part of "                                                                                                                  
##  [60] "A very important discussion on the "                                                                                          
##  [61] "As part of our "                                                                                                              
##  [62] "."                                                                                                                            
##  [63] "Health Care Innovators: A Turning Point in Health IT "                                                                        
##  [64] "."                                                                                                                            
##  [65] "In September 2017, we announced expansion of our safe medication disposal efforts by committing to installing 750 i… "        
##  [66] "."                                                                                                                            
##  [67] "One of "                                                                                                                      
##  [68] "Greater New England Minority Supplier Development Group Honors CVS Health "                                                   
##  [69] "."                                                                                                                            
##  [70] ""                                                                                                                             
##  [71] "."                                                                                                                            
##  [72] "We have more than 1,100 "                                                                                                     
##  [73] "Watch the latest on how we're helping people on their path to better health on our "                                          
##  [74] "Thank you to all U.S. Military service members. We appreciate your commitment to keep our country safe!… "                    
##  [75] "~4,000 students in West Virginia have participated in "                                                                       
##  [76] ""                                                                                                                             
##  [77] ""                                                                                                                             
##  [78] "Sustainable Supplier Partner of the Year: Colgate-Palmolive "                                                                 
##  [79] "."                                                                                                                            
##  [80] "Safely disposing of unwanted or unused medication is one element of our company-wide approach to address the… "               
##  [81] "To learn more about "                                                                                                         
##  [82] "Learn how we’re creating a new paradigm for population health management to improve patient outcomes, lower costs. "          
##  [83] ""                                                                                                                             
##  [84] "."                                                                                                                            
##  [85] "As a front door to health care in more than 10K communities, "                                                                
##  [86] "We recently celebrated the grand opening of a new mock pharmacy in Jennings, MO! Mock pharmacies help students of a… "        
##  [87] "Pharmacists at "                                                                                                              
##  [88] ""                                                                                                                             
##  [89] "."                                                                                                                            
##  [90] "Promoting safe medication disposal is integral in combatting the "                                                            
##  [91] "Now thru 5/26 you can donate $1, $3, or more when you visit a "                                                               
##  [92] "."                                                                                                                            
##  [93] "."                                                                                                                            
##  [94] "."                                                                                                                            
##  [95] "As a "                                                                                                                        
##  [96] "."                                                                                                                            
##  [97] "News | CVS Health Statement on Trump Administration Initiative to Reduce Drug Costs "                                         
##  [98] "DYK: "                                                                                                                        
##  [99] "."                                                                                                                            
## [100] "We’re proud to partner w/ "                                                                                                   
## [101] "Real-time benefit allows prescribers to see specific benefit info for CVS Caremark PBM members &amp; can see cost of dr… "    
## [102] "."                                                                                                                            
## [103] "Read how "                                                                                                                    
## [104] "."                                                                                                                            
## [105] "Beauty in Real Life highlights what beauty means to real women during real life moments. "                                    
## [106] "."                                                                                                                            
## [107] "."                                                                                                                            
## [108] "."                                                                                                                            
## [109] "Moriarty: Over the past 5 years, "                                                                                            
## [110] ""                                                                                                                             
## [111] "Moriarty: "                                                                                                                   
## [112] "Moriarty: "                                                                                                                   
## [113] "Happening Now: "                                                                                                              
## [114] "."                                                                                                                            
## [115] "POS rebate program enables clients to pass on value of negotiated rebates on branded drugs directly to patients whe… "        
## [116] ""                                                                                                                             
## [117] "It’s National Women’s Lung Health Week and "                                                                                  
## [118] "."                                                                                                                            
## [119] "."                                                                                                                            
## [120] "Learn how "                                                                                                                   
## [121] "Pharmacists at "                                                                                                              
## [122] "CVS Caremark provides info on Rx drug costs &amp; savings directly to "                                                       
## [123] "Did you know? Just 5% of population drives ~50% of costs? We’re working to create a new standard for health care en… "        
## [124] "News | At HLTH 2018, CVS Health Chief Medical Officer Shows How Complementary Care Management at Retail Can Enhance… "        
## [125] "MinuteClinic Celebrates First Anniversary of Expanded Access to Care for Arizona Veterans "                                   
## [126] "Learn how "                                                                                                                   
## [127] "."                                                                                                                            
## [128] "."                                                                                                                            
## [129] "The "                                                                                                                         
## [130] "Key "                                                                                                                         
## [131] "."                                                                                                                            
## [132] "."                                                                                                                            
## [133] "."                                                                                                                            
## [134] "Happy "                                                                                                                       
## [135] "New collaboration w/ Job Corps committed to enhance workforce development opportunities for aspiring pharmacy techn… "        
## [136] "Pharmacists at "                                                                                                              
## [137] "Many Americans are paying higher OOP costs for "                                                                              
## [138] "New "                                                                                                                         
## [139] "Beauty in Real Life is first campaign to highlight "                                                                          
## [140] "Our pharmacists &amp; "                                                                                                       
## [141] "Listen to "                                                                                                                   
## [142] "."                                                                                                                            
## [143] "Thank you "                                                                                                                   
## [144] "News | CVS Health Recognized By DiversityInc as Top 50 Company for Diversity For Second Year in a Row "                       
## [145] "Q1 Earnings: Launched the industry’s most comprehensive approach to help make needed medications more affordable, p… "        
## [146] "Q1 Earnings: Per our latest Drug Trend report, in 2017, our PBM strategies reduced drug trend for commercial client… "        
## [147] "Q1 Earnings: We’re continuing to innovate to improve quality &amp; lower the cost of health care for our patients &amp; cli… "
## [148] "Q1 Earnings: “Our initiatives to expand our partnerships, including those with other PBM’s and health plans, have p… "
sent.value
##   [1]  0.00  0.00  3.30  0.00  0.00  0.00  0.50  0.50  0.00  0.50  0.50
##  [12] -0.85  1.50  0.00  1.00  0.00  0.00  1.80  0.00  0.50  1.80  0.00
##  [23]  0.00  0.00  0.30  0.00  0.00  0.00  1.00  1.10  0.50  0.00  3.30
##  [34]  0.00  1.10  0.00  0.40  0.00  0.80  0.00  0.00  0.00  0.00  0.00
##  [45]  0.00  0.00  0.80  0.00  0.00  0.00  3.25  0.80  0.00  2.00  0.00
##  [56]  0.00  0.00  0.90  2.10  0.40  0.00  0.00  2.25  1.25  0.00  0.00
##  [67]  0.00  0.00  0.00  0.00  0.00  2.10  0.00  0.00  1.15  0.00  0.00
##  [78]  1.00  0.00  0.00  0.45  0.00  0.00  0.00  1.05  0.00  0.00  0.00
##  [89]  0.00  0.00  1.30  2.25  0.00  0.15  0.00  0.00  1.80  0.00  0.00
## [100] -0.85  0.80  3.25  0.00  0.00  0.00  1.00  1.55  0.00  1.25  0.00
## [111]  0.00  1.55  0.40  0.00  0.00  0.00  0.00  0.00  0.40  0.00 -0.20
## [122]  0.00  0.00  0.00  1.55  0.75  0.00  0.00  2.50  0.00  0.75  0.00
## [133]  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.80
## [144]  0.60  0.00  0.00  0.00  0.00  0.40  0.80  0.00  0.40  2.65  0.50
## [155]  2.40  1.80  0.80  0.00  3.50  0.00  0.00  0.00  0.00  0.60  0.00
## [166]  0.00  0.75  3.80  2.30  0.00  0.00  0.80  1.35  0.00  0.00  0.00
## [177]  0.00  0.50  0.00  0.00  1.80  0.30  2.65  1.00  0.70
sent.value_rstats 
## [1] 0.00 0.00 0.00 0.75 0.00
positive.tweets <- word.df[sent.value > 0]

head(positive.tweets)
## [1] "Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… "
## [2] "Thank you AG "                                                                                                            
## [3] "We’ve implemented numerous programs &amp; initiatives aimed at diversity in the workplace, like a supplier diversity pr… "
## [4] "CVS Health Shows Support for First Responders "                                                                           
## [5] "Thank you Senator "                                                                                                       
## [6] "Annual OOP health care costs can be significant for many patients. "
positive.tweets_rstats <- word.df[sent.value_rstats > 0]

head(positive.tweets_rstats)
## [1] "We held 450 "                        
## [2] "."                                   
## [3] "Read how "                           
## [4] "."                                   
## [5] ""                                    
## [6] "Addressing Rising Health Care Costs "
negative.tweets <- word.df[sent.value < 0] 
head(negative.tweets)
## [1] "News | CVS Health Expands Safe Drug Disposal at CVS Pharmacy Locations in Virginia to Help Combat Opioid Abuse "
## [2] "Safely disposing of unwanted or unused medication is one element of our company-wide approach to address the… " 
## [3] "News | CVS Health Statement on Trump Administration Initiative to Reduce Drug Costs "
negative.tweets_rstats <- word.df[sent.value_rstats < 0] 
head(negative.tweets_rstats)
## character(0)
neutral.tweets <- word.df[sent.value == 0] 
head(neutral.tweets)
## [1] "."            "."            "We held 450 " "."           
## [5] "."            "."
neutral.tweets_rstats <- word.df[sent.value_rstats == 0] 
head(neutral.tweets_rstats)
## [1] "."                                                                                                                        
## [2] "."                                                                                                                        
## [3] "Learn how Coram CVS Specialty Infusion Services (Coram) &amp; our high-touch model helps provide one-on-one support for… "
## [4] "."                                                                                                                        
## [5] "."                                                                                                                        
## [6] "Thank you AG "
category_senti <- ifelse(sent.value < 0, "Negative", ifelse(sent.value > 0, "Positive", "Neutral"))
 
head(category_senti)
## [1] "Neutral"  "Neutral"  "Positive" "Neutral"  "Neutral"  "Neutral"
category_senti_rstats <- ifelse(sent.value_rstats < 0, "Negative", ifelse(sent.value > 0, "Positive", "Neutral"))
 
head(category_senti_rstats)
## [1] "Neutral"  "Neutral"  "Positive" "Neutral"  "Neutral"
head(category_senti)
## [1] "Neutral"  "Neutral"  "Positive" "Neutral"  "Neutral"  "Neutral"
category_senti2 <- cbind(tweets,category_senti) 

head(category_senti2) #tweets category_senti senti
##      tweets category_senti
## [1,] ?      "Neutral"     
## [2,] ?      "Neutral"     
## [3,] ?      "Positive"    
## [4,] ?      "Neutral"     
## [5,] ?      "Neutral"     
## [6,] ?      "Neutral"
head(category_senti_rstats)
## [1] "Neutral"  "Neutral"  "Positive" "Neutral"  "Neutral"
category_senti2_rstats <- cbind(tweets,category_senti_rstats) 

head(category_senti2_rstats) #tweets category_senti senti
##      tweets category_senti_rstats
## [1,] ?      "Neutral"            
## [2,] ?      "Neutral"            
## [3,] ?      "Positive"           
## [4,] ?      "Neutral"            
## [5,] ?      "Neutral"            
## [6,] ?      "Neutral"
sentiment_categories <- table(category_senti)
sentiment_categories
## category_senti
## Negative  Neutral Positive 
##        3      111       71
sentiment_categories_rstats <- table(category_senti_rstats)
sentiment_categories_rstats
## category_senti_rstats
##  Neutral Positive 
##        4        1

There is more percentage of positive sentiments in the tweets on both CVSHealth and CVSAetna.

plot(table(category_senti), main="Twitter Sentiments")

pie(sentiment_categories, main="Twitter Sentiments", labels=c("Negative","Neutral","Positive"), cex=0.8)