【问题标题】:Check n-words frequency for the open ended questions检查开放式问题的 n 词频率
【发布时间】:2017-07-17 16:27:46
【问题描述】:

我想分析开放式问题的答案。首先是单个词云,然后我想统计2-3个词短语的频率时遇到了一个问题。

这是我的代码:

library('tm')
tokenize_ngrams <- function(x,n=2)return(rownames(as.data.frame(unclass(textcnt(x,method="string",n=n)))))
corpus <- Corpus(VectorSource(texts))
matrix <- TermDocumentMatrix(corpus,control=list(tokenize=tokenize_ngrams))
inspect(matrix[1:4, 1:3])

结果应该是两个词的短语和频率。 但我得到的结果如下:

                 Docs
Terms            1 2 3
document         1 0 0
first            1 0 0
the              1 1 1
this             1 1 1

【问题讨论】:

    标签: r text-mining tm


    【解决方案1】:

    不知道使用 tm 的答案,但这可以正常工作:

    require(quanteda)
    matrix <- dfm(texts, ngrams = 2)
    head(matrix)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 2019-05-25
      • 2014-05-18
      • 2019-02-01
      • 1970-01-01
      相关资源
      最近更新 更多