Text sentiment analysis
#Replacing "/", "@" and "|" with space
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))
TextDoc <- tm_map(TextDoc, toSpace, "/")
TextDoc <- tm_map(TextDoc, toSpace, "@")
TextDoc <- tm_map(TextDoc, toSpace, "\\|")
# Convert the text to lower case
TextDoc <- tm_map(TextDoc, content_transformer(tolower))
# Remove numbers
TextDoc <- tm_map(TextDoc, removeNumbers)
# Remove english common stopwords
TextDoc <- tm_map(TextDoc, removeWords, stopwords("english"))
# Remove your own stop word
# specify your custom stopwords as a character vector
TextDoc <- tm_map(TextDoc, removeWords, c("s", "company", "team"))
# Remove punctuations
TextDoc <- tm_map(TextDoc, removePunctuation)
# Eliminate extra white spaces
TextDoc <- tm_map(TextDoc, stripWhitespace)
# Text stemming - which reduces words to their root form
TextDoc <- tm_map(TextDoc, stemDocument)
## word freq
## louisvill louisvill 1019
## bank bank 792
## shoot shoot 632
## shooter shooter 383
## polic polic 371
## kill kill 265
## mass mass 214
## employe employe 158
## releas releas 155
## livestream livestream 154
## legal legal 143
## call call 140
## gunman gunman 138
## say say 135
## video video 132
## bought bought 129
## kentucki kentucki 126
## gun gun 117
## attack attack 113
## show show 109
## week week 95
## connor connor 91
## ago ago 89
## dead dead 88
## fire fire 81
## sturgeon sturgeon 80
## bodi bodi 80
## rifl rifl 75
## offic offic 75
## know know 66
## camera camera 63
## victim victim 62
## live live 61
## day day 58
## footag footag 56
## updat updat 52
## bodycam bodycam 51
## suspect suspect 49
## peopl peopl 48
## injur injur 46
## vigil vigil 45
## hold hold 44
## shot shot 40
## moment moment 39
## four four 38
## left left 38
## time time 38
## mother mother 38
## chaotic chaotic 37
## wound wound 36
## identifi identifi 34
## ‘ ‘ 34
## massacr massacr 33
## open open 33
## chief chief 33
## citi citi 33
## five five 32
## reveal reveal 31
## hit hit 30
## cowork cowork 29
## outlook outlook 29
## target target 28
## evil evil 28
## will will 28
## just just 27
## report report 26
## cop cop 26
## head head 26
## prior prior 26
## famili famili 25
## murder murder 24
## act act 22
## cte cte 21
## use use 20
## ’ ’ 20
## offici offici 20
## meet meet 20
## test test 20
## brain brain 20
## tough tough 20
## downtown downtown 19
## colleagu colleagu 19
## hope hope 19
## die die 18
## nation nation 18
## old old 18
## news news 17
## stop stop 17
## rampag rampag 17
## purchas purchas 17
## cam cam 17
## graduat graduat 16
## mayor mayor 16
## warn warn 16
## detail detail 16
## academi academi 16
## worker worker 15
## respons respons 15
## new new 15
## friend friend 14
## man man 14
## includ includ 14
## shooter’ shooter’ 14
## law law 13
## yearold yearold 13
## killer killer 13
## investig investig 13
## author author 13
## frantic frantic 13
## remain remain 12
## back back 12
## hospit hospit 12
## toward toward 12
## mourn mourn 12
## school school 12
## parent parent 12
## city’ city’ 12
## ‘tough ‘tough 12
## former former 11
## father father 11
## break break 11
## nine nine 11
## other other 11
## critic critic 11
## tri tri 11
## manag manag 11
## person person 11
## staff staff 11
## made made 10
## audio audio 10
## star star 10
## tennesse tennesse 10
## two two 10
## violenc violenc 10
## control control 10
## action action 10
## – – 9
## motiv motiv 9
## alleg alleg 9
## biden biden 9
## death death 9
## hurt hurt 9
## name name 9
## told told 9
## suffer suffer 9
## plan plan 9
## concuss concuss 9
## led led 9
## sever sever 9
## rush rush 9


## $attack
## numeric(0)
##
## $bank
## numeric(0)
##
## $employe
## numeric(0)
##
## $kill
## numeric(0)
##
## $livestream
## numeric(0)
##
## $louisvill
## numeric(0)
##
## $die
## numeric(0)
##
## $shoot
## numeric(0)
##
## $victim
## numeric(0)
##
## $wound
## numeric(0)
##
## $identifi
## numeric(0)
##
## $pronoun
## ” bio scrub “ antitran inspir
## 0.50 0.50 0.50 0.35 0.35 0.35
## now’ outrag spark bio… circul blame
## 0.35 0.35 0.35 0.35 0.35 0.35
## extremists’ troll ‘pronoun
## 0.35 0.35 0.35
##
## $shooter
## numeric(0)
##
## $use
## numeric(0)
##
## $disgruntl
## exwork session
## 0.52 0.45
##
## $downtown
## numeric(0)
##
## $injur
## numeric(0)
##
## $polic
## numeric(0)
##
## $say
## numeric(0)
##
## $suspect
## numeric(0)
##
## $mass
## numeric(0)
##
## $live
## numeric(0)
##
## $updat
## numeric(0)
##
## $video
## numeric(0)
##
## $dead
## numeric(0)
##
## $kentucki
## numeric(0)
##
## $connor
## numeric(0)
##
## $remain
## numeric(0)
##
## $sturgeon
## numeric(0)
##
## $`–`
## numeric(0)
##
## $`’`
## numeric(0)
##
## $four
## numeric(0)
##
## $know
## numeric(0)
##
## $motiv
## numeric(0)
##
## $peopl
## lock proguncontrol twitter
## 0.39 0.39 0.39
##
## $five
## numeric(0)
##
## $former
## deceas
## 0.43
##
## $gunman
## numeric(0)
##
## $day
## numeric(0)
##
## $gun
## numeric(0)
##
## $law
## numeric(0)
##
## $made
## numeric(0)
##
## $nation
## numeric(0)
##
## $old
## numeric(0)
##
## $yearold
## numeric(0)
##
## $alleg
## lock proguncontrol twitter account
## 0.47 0.47 0.47 0.38
##
## $media
## social antinra post radic glenn greenwald look matt
## 0.71 0.35 0.35 0.35 0.35 0.35 0.35 0.35
## shadier taibbi bama expand medicaid readi forget narrat
## 0.35 0.35 0.35 0.35 0.35 0.35 0.35 0.35
## shower sympathet
## 0.35 0.35
##
## $biden
## joe ireland keep northern peac
## 0.58 0.47 0.47 0.47 0.47
##
## $issu
## polit statement
## 0.45 0.45
##
## $murder
## numeric(0)
##
## $multipl
## career devast momtwo ill
## 0.38 0.38 0.38 0.38
##
## $need
## fact disturb fast somebodi classifi hear leaker patriot
## 0.47 0.47 0.41 0.41 0.41 0.41 0.41 0.41
##
## $report
## numeric(0)
##
## $alabama
## univers grad purchased’ ‘recent univ
## 0.61 0.61 0.41 0.41 0.41
##
## $graduat
## numeric(0)
##
## $friend
## governor’ suspect’
## 0.46 0.46
##
## $arm
## exemploye banker purchased’ ‘recent
## 0.47 0.41 0.41 0.41
##
## $rifl
## numeric(0)
##
## $even
## glenn greenwald look matt shadier taibbi alli appear
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
## doc ntd spi expect gain lynn mahoney riley
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
## sfsu wors didn’t mente regist
## 0.45 0.45 0.45 0.45 0.45
##
## $target
## numeric(0)
##
## $act
## violence’
## 0.42
##
## $everyth
## facts…
## 0.41
##
## $offici
## numeric(0)
##
## $stream
## ‘senseless’ heinous blew nord pipelin russia”
## 0.45 0.45 0.45 0.45 0.45 0.45
## wasn’t
## 0.45
##
## $colleagu
## governor’ suspect’
## 0.4 0.4
##
## $death
## dem gaetz share
## 0.47 0.47 0.38
##
## $pictur
## numeric(0)
##
## $shot
## numeric(0)
##
## $massacr
## numeric(0)
##
## $hurt
## numeric(0)
##
## $audio
## scanner yrold lock proguncontrol twitter
## 0.63 0.55 0.45 0.45 0.45
## nichola pray shooter”—gradu “run closet
## 0.45 0.45 0.45 0.45 0.45
## cower account wilt went everyone’
## 0.45 0.36 0.36 0.36 0.36
## ‘kill
## 0.36
##
## $father
## ‘concussions’ lock proguncontrol twitter degen
## 0.45 0.43 0.43 0.43 0.43
##
## $just
## numeric(0)
##
## $man
## lock proguncontrol twitter arrest
## 0.38 0.38 0.38 0.38
##
## $name
## “suicidal” killersay killer…say lock proguncontrol
## 0.78 0.55 0.55 0.39 0.39
## twitter
## 0.39
##
## $left
## numeric(0)
##
## $job
## earlier move
## 0.61 0.61
##
## $offic
## numeric(0)
##
## $`break`
## silenc “suicidal”
## 0.52 0.43
##
## $fire
## numeric(0)
##
## $open
## numeric(0)
##
## $chief
## numeric(0)
##
## $mayor
## streets’
## 0.43
##
## $ambush
## lobbi
## 0.65
##
## $cop
## quick
## 0.39
##
## $cowork
## numeric(0)
##
## $includ
## numeric(0)
##
## $meet
## virtual murdered’ wit
## 0.44 0.44 0.44
##
## $nine
## numeric(0)
##
## $other
## numeric(0)
##
## $back
## street
## 0.5
##
## $news
## australia australia’ budget cyber games’ hack oversea
## 0.42 0.42 0.42 0.42 0.42 0.42 0.42
## prepar treasur ‘war
## 0.42 0.42 0.42
##
## $worker
## closet cower
## 0.36 0.36
##
## $evil
## numeric(0)
##
## $told
## numeric(0)
##
## $assault
## antitran inspir now’ expect gain lynn mahoney riley
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
## sfsu wors accus charg child crime minor sex
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
##
## $head
## numeric(0)
##
## $may
## australia australia’ budget cyber games’ hack oversea
## 0.71 0.71 0.71 0.71 0.71 0.71 0.71
## prepar treasur ‘war chatroom document origin leak
## 0.71 0.71 0.71 0.58 0.58 0.58 0.47
## ill
## 0.41
##
## $speak
## cincinnati keller tim senseless
## 0.50 0.35 0.35 0.35
##
## $hospit
## numeric(0)
##
## $`‘`
## numeric(0)
##
## $photo
## “suicidal” grin killersay killer…say besid
## 0.53 0.53 0.38 0.38 0.38
##
## $releas
## numeric(0)
##
## $will
## numeric(0)
##
## $athlet
## concussions’ ‘multipl concussions”
## 0.71 0.71 0.41
##
## $star
## concussions’ ‘multipl basketbal
## 0.55 0.55 0.47
##
## $suffer
## concussions’ ‘multipl
## 0.58 0.58
##
## $critic
## wilt nichola pray shooter”—gradu “run
## 0.52 0.43 0.43 0.43 0.43
## among condit
## 0.43 0.43
##
## $rooki
## fight life now heroic standoff harrow
## 0.61 0.53 0.35 0.35 0.35 0.35
##
## $warn
## dem gaetz
## 0.35 0.35
##
## $save
## gunfir ran swift
## 0.43 0.43 0.38
##
## $toward
## gunfir ran nichola pray shooter”—gradu
## 0.50 0.50 0.41 0.41 0.41
## “run
## 0.41
##
## $killer
## numeric(0)
##
## $brief
## numeric(0)
##
## $edt
## numeric(0)
##
## $morn
## oust reinstat headlin lawmak horrifi
## 0.63 0.63 0.52 0.45 0.45
##
## $show
## numeric(0)
##
## $becam
## sportsman
## 0.41
##
## $tennesse
## lawmak oust reinstat headlin
## 0.47 0.45 0.45 0.36
##
## $away
## alik anybodi degre els neighbor touch colleg land
## 0.77 0.77 0.77 0.77 0.77 0.67 0.45 0.45
## loos mile devast momtwo
## 0.45 0.45 0.45 0.45
##
## $detail
## disturb
## 0.43
##
## $academi
## nichola pray shooter”—gradu “run
## 0.35 0.35 0.35 0.35
##
## $ago
## numeric(0)
##
## $hero
## nichola pray shooter”—gradu “run yrold
## 0.58 0.58 0.58 0.58 0.47
## wilt scanner
## 0.47 0.41
##
## $two
## earlier move nichola pray shooter”—gradu
## 0.55 0.55 0.45 0.45 0.45
## “run yrold wilt
## 0.45 0.36 0.36
##
## $week
## numeric(0)
##
## $stop
## fight life
## 0.42 0.36
##
## $tri
## numeric(0)
##
## $governor
## touch alik anybodi degre els neighbor closest analysi
## 0.71 0.61 0.61 0.61 0.61 0.61 0.35 0.35
##
## $one
## alik anybodi degre els neighbor touch closest sicken
## 0.65 0.65 0.65 0.65 0.65 0.57 0.38 0.38
## member
## 0.38
##
## $mourn
## heartbroken
## 0.41
##
## $respond
## bui casualties” alvin block bragg congression
## 0.35 0.35 0.35 0.35 0.35 0.35
## jim lawsuit review crew gallon near
## 0.35 0.35 0.35 0.35 0.35 0.35
## sewag spill
## 0.35 0.35
##
## $note
## wrote apr pst tue
## 0.50 0.35 0.35 0.35
##
## $plan
## numeric(0)
##
## $concuss
## role
## 0.47
##
## $high
## ‘concussions’ basketbal career rais
## 0.71 0.35 0.35 0.35
##
## $school
## ‘concussions’ divid emerson gender quo
## 0.58 0.41 0.41 0.41 0.41
## safeti status
## 0.41 0.41
##
## $manag
## virtual murdered’ wit struck
## 0.60 0.45 0.45 0.43
##
## $saw
## virtual session
## 0.41 0.41
##
## $surviv
## cincinnati grin mentor besid
## 0.58 0.58 0.47 0.41
##
## $tragedi
## cincinnati reel
## 0.53 0.53
##
## $woman
## cincinnati arriv morning’ ‘good
## 0.58 0.41 0.41 0.41
##
## $take
## beast daili auster obit put religi scholar wapo
## 0.63 0.52 0.45 0.45 0.45 0.45 0.45 0.45
## cut facepalm grass nice mindset retir train
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45
##
## $test
## lawyer
## 0.38
##
## $bought
## numeric(0)
##
## $legal
## numeric(0)
##
## $play
## role mentor blm carlson tucker
## 0.63 0.52 0.45 0.45 0.45
##
## $spree
## blm carlson tucker goe church enough shout
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45
##
## $support
## blm carlson tucker helmet divid emerson gender quo safeti status
## 0.76 0.76 0.76 0.53 0.53 0.53 0.53 0.53 0.53 0.53
## poll forget narrat channel major wowk
## 0.44 0.38 0.38 0.38 0.38 0.38
##
## $trump
## concern drug fentanyl hot inquiri mixtur podcast
## 0.53 0.53 0.53 0.53 0.53 0.53 0.53
## price sue veterinari wire manhattan blm carlson
## 0.53 0.53 0.53 0.53 0.43 0.38 0.38
## tucker hater wokest wef threat argument win
## 0.38 0.38 0.38 0.38 0.38 0.38 0.38
## blew nord pipelin russia” wasn’t
## 0.38 0.38 0.38 0.38 0.38
##
## $fifth
## administr claim officer’ devast momtwo adult endur
## 0.38 0.38 0.38 0.38 0.38 0.38 0.38
##
## $reveal
## numeric(0)
##
## $rampag
## numeric(0)
##
## $instagram
## first heinous war
## 0.61 0.41 0.41
##
## $bodi
## numeric(0)
##
## $camera
## numeric(0)
##
## $latest
## oust reinstat headlin lawmak turn
## 0.63 0.63 0.52 0.45 0.45
##
## $respons
## numeric(0)
##
## $footag
## numeric(0)
##
## $around
## numeric(0)
##
## $much
## numeric(0)
##
## $`us…`
## numeric(0)
##
## $microsoft
## dead’ ‘watch session
## 0.41 0.41 0.41
##
## $team
## dead’ ‘watch session
## 0.41 0.41 0.41
##
## $unfold
## don’t mayhem punish ‘pleas
## 0.63 0.63 0.63 0.63
##
## $investig
## ongo
## 0.39
##
## $led
## numeric(0)
##
## $sever
## numeric(0)
##
## $leader
## day’ ‘unthink legisl measur
## 0.38 0.38 0.38 0.38
##
## $person
## numeric(0)
##
## $call
## numeric(0)
##
## $watch
## confer via horrifi
## 0.35 0.35 0.35
##
## $chill
## grin voicemail everyone’ ‘kill besid dispatch threaten everyon
## 0.53 0.53 0.43 0.43 0.38 0.38 0.38 0.38
## second
## 0.38
##
## $famili
## numeric(0)
##
## $sourc
## cooper
## 0.35
##
## $hit
## numeric(0)
##
## $hope
## numeric(0)
##
## $outlook
## numeric(0)
##
## $rush
## fight life
## 0.58 0.50
##
## $cnn
## first disturb
## 0.67 0.52
##
## $minut
## first swift
## 0.53 0.35
##
## $arstyl
## among
## 0.63
##
## $`shooter’`
## scrub
## 0.38
##
## $communiti
## deliber eyeopen read
## 0.35 0.35 0.35
##
## $violenc
## ever american can
## 0.36 0.36 0.36
##
## $six
## public’
## 0.45
##
## $tuesday
## alert xavier
## 0.50 0.35
##
## $staff
## numeric(0)
##
## $author
## numeric(0)
##
## $last
## numeric(0)
##
## $wait
## appeal bobbi brown elizabeth engag holm milli prison
## 0.47 0.47 0.47 0.47 0.47 0.47 0.47 0.47
## trend
## 0.47
##
## $control
## divid emerson gender quo safeti status poll
## 0.45 0.45 0.45 0.45 0.45 0.45 0.36
##
## $mental
## ill danger nutti shock troops’ ‘rile baffl
## 0.35 0.35 0.35 0.35 0.35 0.35 0.35
##
## $emerg
## brew favorit mantra perhap
## 0.35 0.35 0.35 0.35
##
## $cte
## ‘concussions’ lawyer
## 0.43 0.38
##
## $`sturgeon’`
## numeric(0)
##
## $`‘hopeful’`
## numeric(0)
##
## $said
## fit morning’ ‘good
## 0.45 0.45 0.45
##
## $prior
## numeric(0)
##
## $help
## plead mindset retir train
## 0.77 0.45 0.45 0.45
##
## $purchas
## less
## 0.36
##
## $andi
## numeric(0)
##
## $beshear
## numeric(0)
##
## $gov
## numeric(0)
##
## $brain
## diseas lawyer
## 0.38 0.38
##
## $get
## appeal bobbi brown elizabeth engag holm milli prison
## 0.58 0.58 0.58 0.58 0.58 0.58 0.58 0.58
## trend disturb must
## 0.58 0.47 0.41
##
## $bodycam
## numeric(0)
##
## $weapon
## street rage current state’
## 0.47 0.41 0.41 0.41
##
## $republican
## divid emerson gender quo safeti status poll book
## 0.63 0.63 0.63 0.63 0.63 0.63 0.52 0.45
## pronouns’ slam soar lead progun right way channel
## 0.45 0.45 0.45 0.45 0.45 0.45 0.45 0.45
## major wowk
## 0.45 0.45
##
## $action
## numeric(0)
##
## $health
## challenges’ ‘mental
## 0.58 0.58
##
## $tighter
## numeric(0)
##
## $new
## earlier move
## 0.45 0.45
##
## $auction
## public’
## 0.38
##
## $moment
## numeric(0)
##
## $cam
## numeric(0)
##
## $citi
## numeric(0)
##
## $`friend’`
## numeric(0)
##
## $desper
## justreleas
## 0.45
##
## $run
## almost challeng third
## 0.38 0.38 0.38
##
## $superhuman
## numeric(0)
##
## $time
## numeric(0)
##
## $hold
## numeric(0)
##
## $tough
## numeric(0)
##
## $vigil
## numeric(0)
##
## $anyon
## numeric(0)
##
## $frantic
## lord
## 0.39
##
## $mother
## numeric(0)
##
## $never
## signs’ alreadi anyone’ learn
## 0.38 0.38 0.38 0.38
##
## $took
## quick
## 0.89
##
## $parent
## prais
## 0.41
##
## $`heartbroken’`
## numeric(0)
##
## $today
## heartbroken kcra
## 0.50 0.35
##
## $central
## numeric(0)
##
## $explain
## numeric(0)
##
## $floyd
## numeric(0)
##
## $`city’`
## numeric(0)
##
## $`‘tough`
## numeric(0)
##
## $chaotic
## numeric(0)
##
## $`gunman’`
## ‘ambush’ studi
## 0.35 0.35
##
## $panick
## ‘ambush’
## 0.45
##
## $son
## numeric(0)
##
## $mom
## lord plea alreadi anyone’ learn
## 0.63 0.52 0.45 0.45 0.45
##
## $encourag
## numeric(0)
##
## $hour
## numeric(0)
##
## $`‘lean`
## numeric(0)
## [1] 0.00 -1.25 -1.25 -1.25 -1.25 -1.25
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -4.3500 -1.2500 -0.6000 -0.7889 0.0000 1.8500
## [1] 0 -2 -2 -2 -2 -2
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -4.00 -1.00 0.00 -0.54 0.00 2.00
## [1] 0 -4 -4 -4 -4 -4
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -11.000 -3.000 0.000 -1.541 0.000 5.000
## [,1] [,2] [,3] [,4] [,5] [,6]
## [1,] 0 -1 -1 -1 -1 -1
## [2,] 0 -1 -1 -1 -1 -1
## [3,] 0 -1 -1 -1 -1 -1
## anger anticipation disgust fear joy sadness surprise trust negative positive
## 1 0 0 0 0 0 0 0 1 0 1
## 2 1 0 0 1 0 0 0 1 1 0
## 3 1 0 0 1 0 0 0 1 1 0
## 4 1 0 0 1 0 0 0 1 1 0
## 5 1 0 0 1 0 0 0 1 1 0
## 6 1 0 0 1 0 0 0 1 1 0
## 7 1 0 0 1 0 0 0 1 1 0
## 8 2 0 0 2 0 1 0 1 2 0
## 9 2 0 0 2 0 1 0 1 2 0
## 10 0 0 0 1 0 0 0 1 0 0

