为什么即使在tm_map函数中将content_transformer用作lower后,R中的DocumentTerm Matrix也出现错误?

时间:2019-03-10 06:05:15

标签: r text-mining tm

我在这里经历了很多答案,并尝试使用stackoverflow中给出的所有建议,但似乎没有任何用处。在R中使用tm包创建文档术语矩阵之前,有任何顺序吗?

email_corpus <- VCorpus(VectorSource(df2$final_text))

email_corpus_clean <- tm_map(email_corpus,content_transformer(tolower))     

#remove special characters

for(j in seq(email_corpus_clean))  {        

email_corpus_clean[[j]] <- gsub("\n", " ", email_corpus_clean[[j]]) 
email_corpus_clean[[j]] <- gsub("\r", " ", email_corpus_clean[[j]])        
email_corpus_clean[[j]] <- gsub(">>", " ", email_corpus_clean[[j]])     

}


email_corpus_clean <- tm_map(email_corpus_clean,removeNumbers)        

myStopWords<- c("said","from","what")

email_corpus_clean <- tm_map(email_corpus_clean, removeWords, c(stopwords("english"), myStopWords))    

email_corpus_clean <- tm_map(email_corpus_clean, removePunctuation)   

email_corpus_clean <- tm_map(email_corpus_clean, stemDocument)   

email_corpus_clean <- tm_map(email_corpus_clean,stripWhitespace)  

#This is the line of code , where i get error 

email_dtm <- DocumentTermMatrix(email_corpus_clean)   #creating document term matrix


# this is the error 

Error in UseMethod("meta", x) : 
no applicable method for 'meta' applied to an object of class "character"

0 个答案:

没有答案