小编Fou*_*ane的帖子

tm 包中的 DocumentTermMatrix 不返回所有单词

我正在使用 R 中的 tm-package 创建一个文档术语矩阵,但是我的语料库中的一些单词在这个过程中丢失了。

我将用一个例子来解释。假设我有这个小语料库

library(tm)
crps <- " more hours to my next class bout to go home and go night night"
crps <- VCorpus(VectorSource(crps))
Run Code Online (Sandbox Code Playgroud)

当我DocumentTermMatrix()从 tm-package 使用时,它将返回以下结果:

dm <- DocumentTermMatrix(crps)
dm_matrix <- as.matrix(dm)
dm_matrix
# Terms
# Docs and bout class home hours more next night
# 1   1    1     1    1     1    1    1     2
Run Code Online (Sandbox Code Playgroud)

然而,我想要的(和期望的)是:

# Docs and bout class home hours more next night my  go to
#  1   1    1     1 …
Run Code Online (Sandbox Code Playgroud)

r text-mining tm

3
推荐指数
1
解决办法
1310
查看次数

标签 统计

r ×1

text-mining ×1

tm ×1