R Text mining - how to change texts in R data frame column into several columns with bigram frequencies?

半世苍凉 提交于 2019-11-30 16:31:23

The dev version of qdap (should go to CRAN within the next few days) does ngrams. For now you'll need to use the dev version. On the toy data set this is fast but on a larger data set such as qdap's mraja1 data set requires ~5 minutes to complete. You could:

  1. Select the bigrams more wisely (i.e., don't use them all as there's going to be a ton)
  2. Wait the time
  3. Run it in parallel
  4. Figure out another way to do this
  5. Get a faster computer

Here's the code to get the dev version of qdap and run the bigram search:

library(devtools)
install_github("qdap", "trinker")
library(qdap)

## this gets the bigrams
bigrams <- sapply(ngrams(DATA$state)[[c("all_n", "n_2")]], paste, collapse=" ")

## This searches by grouping variable for bigram use
termco(DATA$state, DATA$person, bigrams)


## To get raw values
termco(DATA$state, DATA$person, bigrams)[["raw"]]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!