Adding custom stopwords in R tm

前端 未结 5 1457
梦谈多话
梦谈多话 2020-12-31 07:15

I have a Corpus in R using the tm package. I am applying the removeWords function to remove stopwords

tm_map(abs, removeWords, stop         


        
5条回答
  •  -上瘾入骨i
    2020-12-31 07:31

    Save your custom stop words in a csv file (ex: word.csv).

    library(tm)
    stopwords <- read.csv("word.csv", header = FALSE)
    stopwords <- as.character(stopwords$V1)
    stopwords <- c(stopwords, stopwords())
    

    Then you can apply custom words to your text file.

    text <- VectorSource(text)
    text <- VCorpus(text)
    text <- tm_map(text, content_transformer(tolower))
    text <- tm_map(text, removeWords, stopwords)
    text <- tm_map(text, stripWhitespace)
    
    text[[1]]$content
    

提交回复
热议问题