[R] LIWC 사용예제(감성분석)

 

#install.packages("devtools")
#devtools::install_github("kbenoit/quanteda")
library(devtools)
library(quanteda)
## quanteda version 0.9.5.23
## 
## Attaching package: 'quanteda'
## The following object is masked from 'package:base':
## 
##     sample
mfdict <- dictionary(file = "http://ow.ly/VMRkL", format = "LIWC") 
## Warning in lapply(catlist[2:ncol(catlist)], as.integer): 강제형변환에 의해
## 생성된 NA 입니다

## Warning in lapply(catlist[2:ncol(catlist)], as.integer): 강제형변환에 의해
## 생성된 NA 입니다
mydfm <- dfm(inaugTexts, dictionary = mfdict)
## 
##    ... lowercasing
##    ... tokenizing
##    ... indexing documents: 57 documents
##    ... indexing features: 9,215 feature types
##    ... applying a dictionary consisting of 11 keys
##    ... created a 57 x 11 sparse dfm
##    ... complete. 
## Elapsed time: 0.87 seconds.
mydfm
## Document-feature matrix of: 57 documents, 11 features.
topfeatures(mydfm, decreasing=TRUE)
##   IngroupVirtue AuthorityVirtue      HarmVirtue  FairnessVirtue 
##            1387            1039             895             567 
##        HarmVice MoralityGeneral     IngroupVice    PurityVirtue 
##             405             319             226              90 
##    FairnessVice   AuthorityVice 
##              88              51
features(mydfm)
##  [1] "HarmVirtue"      "HarmVice"        "FairnessVirtue" 
##  [4] "FairnessVice"    "IngroupVirtue"   "IngroupVice"    
##  [7] "AuthorityVirtue" "AuthorityVice"   "PurityVirtue"   
## [10] "PurityVice"      "MoralityGeneral"
a=as.matrix(mydfm)
b=as.data.frame(a)
sum(b$PurityVice)
## [1] 28

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다