I have a list comprised of words.
> head(splitWords2)
[[1]]
[1] "Some" "additional" "information" "that" "we" "would" "need" "to" "replicate" "the"
[11] "experiment" "is" "how" "much" "vinegar" "should" "be" "placed" "in" "each"
[21] "identical" "container" "or" "what" "tool" "use" "measure" "mass" "of" "four"
[31] "different" "samples" "and" "distilled" "water" "rinse" "after" "taking" "them" "out"
[[2]]
[1] "After" "reading" "the" "expirement" "I" "realized" "that" "additional" "information" "you"
[11] "need" "to" "replicate" "expireiment" "is" "one" "amant" "of" "vinegar" "poured"
[21] "in" "each" "container" "two" "label" "containers" "before" "start" "yar" "and"
[31] "three" "write" "a" "conclusion" "make" "sure" "results" "are" "accurate"
I have a vector of words that I want to count the occurrences of in EACH element of the list, NOT the total number of occurrences in the entire list.
I think the way to do it is a combination of the str_count()
function from the stringr
package and one of the *ply()
functions, but I can't make it work.
numWorder1 <- sapply(ifelse(str_count(unlist(splitWords2), ignore.case("we" ) )> 0, 1, 0))
where "we" will eventually be a word from a vector of words to count occurrences of .
My ideal output would be something like:
lineNum count
1 0
2 1
3 1
4 0
... ...
Any suggestions?