This comes from r remove sparse terms by type of documents. Now I have two TermDocumentMatrix to remove sparse terms, I have tried this but it doesn't work. Any ideas?
library(tm)
library(Rstem)
data(crude)
spl <- runif(length(crude)) < 0.7
crude_1 <- crude[spl]
crude_2 <- crude[!spl]
controls <- list(
tolower = TRUE,
removePunctuation = TRUE,
stopwords = stopwords("english"),
stemming = function(word) wordStem(word, language = "english")
)
tdm_1 <- TermDocumentMatrix(crude_1, controls)
tdm_2 <- TermDocumentMatrix(crude_2, controls)
## Don“t work.
for(i in 1:2){
assign(paste0("TDM_", i),
removeSparseTerms(paste0('tdm_', i), 0.98)
}
## But this is ok.
removeSparseTerms(tdm_1, 0.98)
Thanks again!