R liczba razy słowo pojawia się w elemencie listy
Mam listę zawierającą słowa.
> 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"
Mam wektor słów, które chcę policzyć wystąpienia w KAŻDY element listy, NIE łączną liczbę wystąpień na całej liście.
Myślę, że sposobem na to jest połączeniestr_count()
funkcja zstringr
pakiet i jeden z*ply()
funkcje, ale nie mogę tego zrobić.
numWorder1 <- sapply(ifelse(str_count(unlist(splitWords2), ignore.case("we" ) )> 0, 1, 0))
gdzie „my” w końcu będzie słowem z wektora słów do zliczania wystąpień.
Moim idealnym wyjściem byłoby coś w rodzaju:
lineNum count
1 0
2 1
3 1
4 0
... ...
Jakieś sugestie?