2

Screenshot of the data frame resultI wanted to do sentimental analysis in R using qdap package. It gives out a data frame containing all.all, all.wc, all.polarity, all.pos.words, all.neg.words etc.

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.

dput(head(sentiment))

list(structure(list(all = c("all", "all", "all"), wc = c(44L, 
1L, 1L), polarity = c(-0.422115882408869, 0, 0), pos.words = list(
    "-", "-", "-"), neg.words = list(c("disappointed", "issue"
), "-", "-"), text.var = c("list(list(content = \"  misleaded  icici bank customer care  branch excutive    really disappointed   bank dont know  steps   take  get  issue fixed\", meta = list(author = character(0), datetimestamp = list(sec = 20.097678899765, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), heading = character(0), id = \"1\", language = \"en\", origin = character(0))))", 
"list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
"wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"), 
    structure(list(all = c("all", "all", "all"), wc = c(61L, 
    1L, 1L), polarity = c(0, 0, 0), pos.words = list("led", "-", 
        "-"), neg.words = list("expire", "-", "-"), text.var = c("list(list(content = \" didnt know   customer banking  icici   years will  led    people   looking  student travel card   staff  mg road     treat customers  tried  offer  card  wud expire  one year n told  get  new card  one year    dont know\", meta = list(author = character(0), datetimestamp = list(sec = 20.3989679813385, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), heading = character(0), id = \"1\", language = \"en\", origin = character(0))))", 
    "list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
    "wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"), 
    structure(list(all = c("all", "all", "all"), wc = c(58L, 
    1L, 1L), polarity = c(0, 0, 0), pos.words = list("top", "-", 
        "-"), neg.words = list("worst", "-", "-"), text.var = c("list(list(content = \"  asked   staff    can upgrade  platinum  coral card   documentation  fee will  involoved  even  receiving  card poeple sill keep calling   top      levied  rs joining fee    interested  paying     card  one   worst customer care   experienced\", meta = list(author = character(0), datetimestamp = list(sec = 20.648964881897, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), heading = character(0), id = \"1\", language = \"en\", \n    origin = character(0))))", 
    "list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
    "wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"), 
    structure(list(all = c("all", "all", "all"), wc = c(59L, 
    1L, 1L), polarity = c(-0.494717861727131, 0, 0), pos.words = list(
        "-", "-", "-"), neg.words = list(c("long time", "long time", 
    "disappointed"), "-", "-"), text.var = c("list(list(content = \" applied   credit card   corporate scheme long time back got  verification call also long time back initially   getting  least  response   executive  now    longer picking   call neither letting  know  status   application extremely disappointed   service\", meta = list(author = character(0), datetimestamp = list(sec = 20.8989698886871, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), heading = character(0), id = \"1\", \n    language = \"en\", origin = character(0))))", 
    "list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
    "wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"), 
    structure(list(all = c("all", "all", "all"), wc = c(66L, 
    1L, 1L), polarity = c(0.0246182981958665, 0, 0), pos.words = list(
        c("work", "support"), "-", "-"), neg.words = list("disappointed", 
        "-", "-"), text.var = c("list(list(content = \" otp service   working    used  work   month     decided  change everything im  getting  otp sms   registered mobile number ive tried contacting  customer support several times   keep asking   send  sms   despite  done  several times  several days  havent received  otps ever really disappointed\", meta = list(author = character(0), datetimestamp = list(sec = 21.1935319900513, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), \n    heading = character(0), id = \"1\", language = \"en\", origin = character(0))))", 
    "list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
    "wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"), 
    structure(list(all = c("all", "all", "all"), wc = c(50L, 
    1L, 1L), polarity = c(-0.282842712474619, 0, 0), pos.words = list(
        "-", "-", "-"), neg.words = list(c("pathetic", "lied"
    ), "-", "-"), text.var = c("list(list(content = \"  pathetic service  behavior  icici bank   facing  past  days icici executive lied  luring   upgrade  debit card terms  conditions  just opposite   booklet   received    told  phone\", meta = list(author = character(0), datetimestamp = list(sec = 21.4258019924164, min = 51, hour = 11, mday = 6, mon = 6, year = 115, wday = 1, yday = 186, isdst = 0), description = character(0), heading = character(0), id = \"1\", language = \"en\", origin = character(0))))", 
    "list()", "list()")), row.names = c(NA, -3L), .Names = c("all", 
    "wc", "polarity", "pos.words", "neg.words", "text.var"), class = "data.frame"))

Can anyone suggest how to do this?

Bitanshu Das
  • 627
  • 2
  • 8
  • 21
  • 1
    Please show some reproducible example data. For guidelines, check [here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – akrun Jul 06 '15 at 09:49
  • Using polarity function of qdap package on any text produces same data frame – Bitanshu Das Jul 06 '15 at 09:58
  • 1
    May be it is the case. Could you update your post with some text? – akrun Jul 06 '15 at 10:03
  • i was trying to post the screenshots but didnt had the required priviledges – Bitanshu Das Jul 06 '15 at 10:41
  • 1
    Please don't post images as others have to manually type it from the images. The link I commented above gives ideas about posting. – akrun Jul 06 '15 at 10:42
  • Its a result after using polarity function – Bitanshu Das Jul 06 '15 at 12:14
  • I tried the example from the help page of `?polarity`. i.e. `poldat2 <- with(mraja1spl, polarity(dialogue,list(sex, fam.aff, died)))`, but it is not giving this `all.poswords` or `all.neg.words`. Can you show the code you used or if you can quote the example from the help page, it would be great – akrun Jul 06 '15 at 12:19
  • It was a text file named data. I used sentiment = polarity(data) after removing spaces,stopwords, numbers etc. The output table is shown in the pic above. I just need the negative words and polarity. I had used sentiment$all.polarity but its giving NULL. – Bitanshu Das Jul 06 '15 at 12:21
  • As I mentioned, I am not getting the same output with the example in the help page. It may be better to post the dput output. i..e `dput(head(sentiment))` – akrun Jul 06 '15 at 12:24
  • Can you try `head(sentiment[[1]][1])` If you get the all.all, then probably, you can extend that to `sentiment[[1]][2]` etc. – akrun Jul 06 '15 at 12:27
  • 1
    head(sentiment[[1][3]]) works. Thanks – Bitanshu Das Jul 06 '15 at 12:59
  • You could post that as a solution and close this. – akrun Jul 06 '15 at 13:04
  • It's a list not a dataframe. Use `str` to see. The examples give more on accessing the pieces. – Tyler Rinker Jul 07 '15 at 02:46

1 Answers1

2

The following works for me -

 library(qdap)

 text <- "I am liking the work "  # the text for which polarity score is needed

 sentiment <- polarity(text) #make the call 

 sentiment$all$pos.words # returns the positive words detected by the algo
 #[[1]]
 #[1] "liking" "work"  

 sentiment$all$polarity # returns the sentence polarity score 
 #[1] 0.8944272
Indi
  • 1,401
  • 13
  • 30