removeCommonTerms函数是TM包的here函数,因此
removeCommonTerms <- function (x, pct)
{
stopifnot(inherits(x, c("DocumentTermMatrix", "TermDocumentMatrix")),
is.numeric(pct), pct > 0, pct < 1)
m <- if (inherits(x, "DocumentTermMatrix"))
t(x)
else x
t <- table(m$i) < m$ncol * (pct)
termIndex <- as.numeric(names(t[t]))
if (inherits(x, "DocumentTermMatrix"))
x[, termIndex]
else x[termIndex, ]
}现在,我想删除与泉泰集团过于常见的条款。我可以在创建文档特征矩阵或使用文档特征矩阵之前完成此删除。
如何删除R?中的全德达包中过于常见的术语
发布于 2017-01-11 17:07:20
您需要dfm_trim函数。来自?dfm_trim
max_docfreq出现某一功能的文档的最大数量或部分,在此基础上将删除该功能。(默认值不是上限。)
这需要最新版本的quanteda (新鲜的CRAN)。
packageVersion("quanteda")
## [1] ‘0.9.9.3’
inaugdfm <- dfm(data_corpus_inaugural)
dfm_trim(inaugdfm, max_docfreq = .8)
## Removing features occurring:
## - in more than 0.8 * 57 = 45.6 documents: 93
## Total features removed: 93 (1.01%).
## Document-feature matrix of: 57 documents, 9,081 features (92.4% sparse).https://stackoverflow.com/questions/41589266
复制相似问题