KRU
KRU

Reputation: 291

R: Count the Occurrence of words in list to create benchmark

I have list that consist of words:

$text
$text[[1]]
 [1] "qlikview" "gpa"      "access"   "gpa"      "access"   "access"   "qlikview" "gpa"      "access"  
[10] "gpa"     

$text[[2]]
 [1] "report"   "qlikview" "gpa"      "access"   "qlikview" "gpa"      "access"   "qlikview" "gpa"     
[10] "access"`  

$text[[3]]
 [1] "qlikview" "gpa"      "access"   "gpa"      "access"   "access"   "qlikview" "gpa"      "access"  
[10] "gpa"     

$text[[4]]
 [1] "qlikview" "gpa"      "access"   "gpa"      "access"   "access"   "qlikview" "gpa"      "access"  
[10] "gpa"     

$text[[5]]
 [1] "report"   "qlikview" "gpa"      "access"   "access"   "gpa"      "access"   "qlikview" "gpa"     
[10] "access"   "access"   "gpa"      "qlikview" "gpa"      "access"   "qlikview" "gpa"      "access"

I need to count the number of words occurring in each row of list and plot. I have tried with various ways, but effective only within sentence. Please refer this. Could somebody who has worked on such could help!

edit

dput(O)
O <- structure(list(text = list(c("report", "gpa", "access", "access", 
                                  "access", "gpa", "access", "gpa", 
                                  "access"), c("report", "report", 
                                  "access", "report", "report", "data",  
                                  "report", "report"), 
                                c("report", "qlikview", "gpa", "access", 
                                  "access", "qlikview", "gpa", "access", 
                                  "access", "qlikview", "gpa", "access", 
                                  "access", "qlikview", "gpa", "access"), 
                                  character(0),
                                c("gpa", "gpa", "gpa", "gpa", "gpa", 
                                  "gpa", "gpa", "gpa", "gpa", "gpa", 
                                  "gpa", "gpa"), 
                                c("report", "qlikview", "gpa", "access", 
                                  "access", "qlikview", "gpa", "access", 
                                  "qlikview", "gpa", "access", "access", 
                                  "gpa", "qlikview", "gpa", "access"), 
                                c("report", "data", "data"), 
                                c("report", "report", "report", "data", 
                                  "report", "report"))), .Names = "text")

Upvotes: 1

Views: 166

Answers (1)

akrun
akrun

Reputation: 887501

Try

library(qdapTools)
res <- mtabulate(O$text)
dim(res)
#[1] 244   8

head(res,3)
#   access adhoc data gpa maturity pfi qlikview report
#1      4     0    0   4        0   0        2      0
#2      3     0    0   3        0   0        3      1
#3      4     0    0   4        0   0        2      0

Based on the new dput output (on a small subset)

res1 <- mtabulate(O$text)
head(res1,3)
#  access data gpa qlikview report
#1      5    0   3        0      1
#2      1    1   0        0      6
#3      7    0   4        4      1

Upvotes: 2

Related Questions