我有一个由单词组成的列表。
> 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"
我有一个单词向量,我想计算列表的每个元素中出现的次数,而不是整个列表中出现的总数。
我认为这样做的方法是结合包中的str_count()
功能stringr
和其中一个*ply()
功能,但我无法使其工作。
numWorder1 <- sapply(ifelse(str_count(unlist(splitWords2), ignore.case("we" ) )> 0, 1, 0))
其中“我们”最终将是来自单词向量的单词,用于计算 .
我理想的输出是这样的:
lineNum count
1 0
2 1
3 1
4 0
... ...
有什么建议么?