R count times word appears in element of list

前端 未结 4 675
误落风尘
误落风尘 2020-12-20 04:51

I have a list comprised of words.

> head(splitWords2)
[[1]]
 [1] \"Some\"        \"additional\"  \"information\" \"that\"        \"we\"          \"would\"         


        
4条回答
  •  失恋的感觉
    2020-12-20 05:12

    Something like this:

    wordlist <- list(
        c("the","and","it"),
        c("we","and","it")
    )
    require(plyr); require(stringr)
    > ldply(wordlist, function(x) str_count(x, "we"))
      V1 V2 V3
    1  0  0  0
    2  1  0  0
    

提交回复
热议问题