0

I have gone through many answers here , and tried to use all suggestions given in stackoverflow but nothing seems to be working for me . Is there any order before creating document term matrix using tm package in R ?

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"
Yogesh Kumar
  • 609
  • 6
  • 22
  • From what I can see, the meta type information is causing issues for you. If you only want to parse the body of the email remove the meta data – Dinesh.hmn Mar 10 '19 at 06:14
  • @Dinesh.hmn : How to remove meta data ? – Yogesh Kumar Mar 10 '19 at 06:16
  • can you share a few rows of the data? – Dinesh.hmn Mar 10 '19 at 06:16
  • Text huge even for a row ...here goes sample data "as.character(email_corpus[[2]]) [1] "Configuration Assistance User Agent User / IP map\nUseTools.exeto dump the user/IP map and validate data\nSelect * from user_ip_mappings\n\nThis shows only users that are within the non-natted network co-located behind the ASA." – Yogesh Kumar Mar 10 '19 at 06:21
  • Possible duplicate of [R-Project no applicable method for 'meta' applied to an object of class "character"](https://stackoverflow.com/questions/24771165/r-project-no-applicable-method-for-meta-applied-to-an-object-of-class-charact) – Dinesh.hmn Mar 10 '19 at 06:23
  • I have already tried suggested suggestions given in the link ....I have already used content_transformer(tolower).....it did not work for me – Yogesh Kumar Mar 10 '19 at 06:26
  • did you try corpus <- tm_map(corpus, PlainTextDocument) – Dinesh.hmn Mar 10 '19 at 06:28
  • I tried that , did not work for me .. code that u suggested using "email_corpus_clean <- tm_map(email_corpus,tolower) email_corpus_clean <- tm_map(email_corpus_clean, PlainTextDocument)" – Yogesh Kumar Mar 10 '19 at 14:23

0 Answers0