R count times word appears in element of list

前端 未结 4 686
误落风尘
误落风尘 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:24

    You could always stick to grep in the base package for simplicity...

    LinesList <- list ( "1"=letters[1:10], "2"=rep(letters[1:3],3) )
    CountsA <- grep("[a]", LinesList) # find 'a' in each element of list
    length(CountsA) <- length(LinesList) # gives NAs if not counted
    data.frame( lineNum = names(LinesList), count = CountsA)
    

提交回复
热议问题