I have a list of words.
& gt; We need "" "to repeat" head "(split words 2) [1]] [1]" repeat "" some "" extra "" "" "" "" "" [11] "experiment" Using "" "" "" "" "" "" "" "" "" "" "" "" [21] "in the same" container "or" "" "" "" "" "" "" "" "" "" "" "" "" "" "Out of" "" "four" [31] "separate" "samples" and "distortion" "rinse" "" "" "" "" [2]] [1] " "" After reading "" I need to "" "" "" "" "" extra "" information "" [11] "repeat" "repeat" and "[31] "Before" "" " Each "container" "two" label "container" "" "" "" "" "" "" "" "" writing "" "conclusion" "" " I have a vector of such words, which I want to count events in each element of the list, events that occur in the entire list. Not the total number of I think the way to do this is a combination of str_count () stringr package and * ply () One of the functions, but I can not work it numWorder1 & lt; - sapply (ifelse (str_count (list (split words 2), ignore.case ("we")> gt; 1, 0)) Where "we" The events of being a word from a vector will count.
My ideal production would be something like:
line number 1 0 2 1 3 1 4 0 ... ... Any suggestions?
For a specific term:
word & lt; - $ 1 [1] - list (a = c ("a", "a", "a", "b"), b = c ("w", "w", "q", "a")) "A" "B" "c" "a" "a" b "$ b [1]" w "" w "" q "" a "wt & lt; - data.frame (linename = 1: length (words ) Wt $ Count & lt; - sapply (word, work (x) sum (str_count (x, "a"))) Line number 1 1 3 2 2 1 If vector w is the word you want to count: w <-> ( Lt; lapply (w, function z) data.frame (lineNum = 1: length (words), calculation = sapply (word, work (x) sum (str_count (x, z)))) name (elds) Lt; - w $ one line count counts 1 3b2 1 $ q lineNum 1b2 1 dollar e line counting Not a 1 0 B 2 0
Comments
Post a Comment