How to get frequency of word in a sentence in R?

若如初见. 提交于 2019-12-01 14:50:58

If you gave a little more info I could probably provide more info in return. Using qdap you could:

library(qdap)

dat <- readLines(n=5)
train is good   1
let the train come      5
train is best   3
i m great       3
what is best    2

dat <- do.call(rbind.data.frame, strsplit(dat, "   +"))

colnames(dat) <- c("Text", "Index")

termco(dat$Text, , " train ")

## > termco(dat$Text, , " train ")
##   all word.count     train
## 1 all         16 3(18.75%)

You could probably do all the paragraphs at once with termco. For more on termco see this link.

Alot of this depends on what's separating paragraphs, how you're reading it in, how things are indented etc.

The poster found the following useful:

length(gregexpr("the", "the dog ate the word the", fixed = TRUE)[[1]])

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!