【问题标题】:Joining Term-Document-Matrix with a matix or a list将 Term-Document-Matrix 与矩阵或列表连接起来
【发布时间】:2015-11-22 04:53:16
【问题描述】:

我生成了一个 Term-Document-Matrix,现在我想根据单词列表选择 Term-Document-Matrix 中的术语。所以我打算将 Term-Document-Matrix 与列表结合起来,并删除不完整的行。

我只找到组合两个 Term-Document-Matrix 的方法,但没有找到将 Term-Document-Matrix 与列表或矩阵组合的方法。这该怎么做?

这是列表 negemo

             V1
             1 unpleasant
             2      grief
             3       sobs
             4    sobbing
             5     raging
             6      mourn

【问题讨论】:

    标签: r matrix


    【解决方案1】:

    如果您有一个单词列表作为向量,您可以在创建文档术语矩阵时使用字典命令。

    查看示例:

    library(tm)
    data("crude")
    crude <- as.VCorpus(crude)
    crude <- tm_map(crude, content_transformer(tolower))
    crude <- tm_map(crude, removePunctuation)
    crude <- tm_map(crude, removeNumbers)
    crude <- tm_map(crude, removeWords, stopwords("smart"))
    crude <- tm_map(crude, stripWhitespace)
    crude <- tm_map(crude, stemDocument)
    
    # List of words
    low <- c("price", "oil", "barrel", "contract")
    
    # restict dtm to list of words
    dtm <- DocumentTermMatrix(crude, control=list(dictionary = lib))
    
    head(inspect(dtm))
    
         Terms
    Docs  barrel contract oil price
      127      2        2   5     5
      144      0        0  12     6
      191      1        1   2     2
      194      1        1   1     2
      211      0        0   1     0
      236      4        0   7     8
    

    【讨论】:

      猜你喜欢
      • 2017-12-02
      • 2012-10-29
      • 2020-11-07
      • 2013-10-21
      • 2014-08-05
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 2014-08-16
      相关资源
      最近更新 更多