0
votes

Presently, I'm using the function DocumentTermMatrix() in R to fit LDA model. In addition to the default stop words, I want to add my own words which are supposed to be removed.

library(tm)
myStopwords <- c("aa", "bb")
dtm <- DocumentTermMatrix(myCorpus,
                           control = list(
                           tolower = TRUE,
                           removePunctuation = TRUE,
                           removeNumbers= TRUE,
                           stemming = FALSE,
                           stopwords = TRUE,
                           minWordLength = 2))

Can one help me on how to add my own stop words in the above code? Thank you!

1

1 Answers

2
votes

You can add your own stop words by adding removeWords = c("aa", "bb") inside the DocumentTermMatrix function.

library(tm)
myStopwords <- c("aa", "bb")
dtm <- DocumentTermMatrix(myCorpus,
                           control = list(
                           tolower = TRUE,
                           removePunctuation = TRUE,
                           removeNumbers= TRUE,
                           stemming = FALSE,
                           stopwords = TRUE,
                           removeWords = c("aa","bb"),
                           minWordLength = 2))
))