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

后端 未结 1 1233
忘了有多久
忘了有多久 2021-01-03 17:28

In addition to question R Text mining - how to change texts in R data frame column into several columns with word frequencies? I am wondering how I can manage to make column

相关标签:
1条回答
  • 2021-01-03 18:09

    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"]]
    
    0 讨论(0)
提交回复
热议问题