【问题标题】:Remove specific word from a dfm从 dfm 中删除特定单词
【发布时间】:2020-11-27 19:15:57
【问题描述】:

从这个过程

    library(stm)
library(tidyr)
library(quanteda)
     testDfm <- gadarian$open.ended.response %>%
             tokens(remove_punct = TRUE, remove_numbers = TRUE, remove_symbols = TRUE)  %>%
             dfm()

假设我们检查了 frq

dftextstat <- textstat_frequency(testDfm)

我们想从 dfm 中删除一些特定的单词。根据我们要删除的dftextstat c("and", "to") 有什么方法可以在dfm中制作它而无需再次运行这些行来创建dfm?

【问题讨论】:

  • 你能做一个可重现的例子吗
  • @akrun 是的,请查看更新的代码

标签: r quanteda


【解决方案1】:

如果您已经有 dfm,可以使用 dfm_remove 删除功能。

根据您的示例:

# remove "and" and "to"
testDfm <- dfm_remove(testDfm, c("and", "to"))

最好删除所有停用词:

dfm_remove(testDfm, stopwords("english"))

如果你还有一个令牌对象,你可以用同样的方式使用tokens_remove,或者在你上面的管道中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2013-08-25
    • 2014-07-03
    相关资源
    最近更新 更多