trinker / qdap

Quantitative Discourse Analysis Package: Bridging the gap between qualitative data and quantitative analysis
http://cran.us.r-project.org/web/packages/qdap/index.html
175 stars 44 forks source link

Issue with Common function and extracting all.polarity #213

Closed bitanshu closed 9 years ago

bitanshu commented 9 years ago

Hello everyone,

Thanks for this wonderful package. I am currently facing two issues while working with qdap function.

  1. When I use common package to search for common strings, it works perfectly fine when it finds common strings but throws up an error when it doesnt rather than giving NULL or False output. Any solution for this?
  2. When I find out the polarity of a text, it gives out the polarity dataframe. I want to extract the values of all.polarity, all.pos.words,all.neg.words but when i use sentiment$all.polarity or sentiment$all.pos.words,

I get NULL in result.

Can anyone suggest how to do this?

trinker commented 9 years ago

Thanks for your feedback...

When I use common package to search for common strings, it works perfectly fine when it finds common strings but throws up an error when it doesnt rather than giving NULL or False output. Any solution for this?

This has been implemented in the dev version. In the news file it states

When I find out the polarity of a text, it gives out the polarity dataframe. I want to extract the values of all.polarity, all.pos.words,all.neg.words but when i use sentiment$all.polarity or sentiment$all.pos.words,

Here you need to use str to look at the object and you'd see polarity does not return a data.frame but a list. You can access the pieces as shown below:

(poldat <- with(sentSplit(DATA, 4), polarity(state, person)))
str(poldat)

## List of 2
##  $ all  :'data.frame':  15 obs. of  6 variables:
##   ..$ person   : Factor w/ 5 levels "greg","researcher",..: 4 4 1 5 4 1 3 1 4 3 ...
##   ..$ wc       : int [1:15] 3 3 5 4 4 5 5 4 3 5 ...
##   ..$ polarity : num [1:15] 0.577 -0.577 -0.447 0 -1 ...
##   ..$ pos.words:List of 15
##   .. ..$ : chr "fun"
##   .. ..$ : chr "fun"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "good"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   ..$ neg.words:List of 15
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "dumb"
##   .. ..$ : chr "-"
##   .. ..$ : chr [1:2] "liar" "stinks"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "distrust"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   .. ..$ : chr "-"
##   ..$ text.var : chr [1:15] "Computer is fun." "Not too fun." "No it's not, it's dumb." "What should we do?" ...
##  $ group:'data.frame':  5 obs. of  6 variables:
##   ..$ person            : Factor w/ 5 levels "greg","researcher",..: 1 2 3 4 5
##   ..$ total.sentences   : int [1:5] 6 2 2 4 1
##   ..$ total.words       : int [1:5] 20 6 10 13 4
##   ..$ ave.polarity      : num [1:5] -0.0745 0.3536 0 -0.3943 0
##   ..$ sd.polarity       : num [1:5] 0.183 0.5 0 0.678 NA
##   ..$ stan.mean.polarity: num [1:5] -0.408 0.707 NaN -0.582 NA
##  - attr(*, "class")= chr [1:2] "polarity" "list"
##  - attr(*, "digits")= num 3
##  - attr(*, "constrained")= logi FALSE
##  - attr(*, "unconstrained.polarity")= num [1:15] 0.577 -0.577 -0.447 0 -1 ...

counts(poldat)
counts(poldat)[["neg.words"]]
scores(poldat)
bitanshu commented 9 years ago

Thanks trinker