0

My previous code has been as below -

corpus <- VCorpus(VectorSource(final_data$comment))
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeWords, stopwords())
corpus <- tm_map(corpus, stemDocument)
corpus <- tm_map(corpus, removeWords, 'brw')
corpus <- tm_map(corpus, removeWords, 'cid')
corpus <- tm_map(corpus, stripWhitespace)
corpus <- tm_map(corpus, trimws)
dtm <- DocumentTermMatrix(corpus)

I am getting following error on last command (DocumentTermMatrix) -

'no applicable method for 'meta' applied to an object of class "character"'

Can you please let me know how to fix it ?

phiver
  • 23,048
  • 14
  • 44
  • 56
  • Seems like a duplicate. Check this [link](https://stackoverflow.com/questions/24771165/r-project-no-applicable-method-for-meta-applied-to-an-object-of-class-charact) – SidharthMacherla Apr 20 '20 at 04:07

1 Answers1

0

The use of this line of code is causing an issue tm_map(corpus, trimws). The result is a character string instead of the document. This messes up the corpus. If you want to use other function within tm_map that is not part of the tm package, you need to use the function content_transformer.

If you change your last line of code to the one below it should work.

corpus <- tm_map(crude, content_transformer(function(x) trimws(x)))
dtm <- DocumentTermMatrix(corpus)
phiver
  • 23,048
  • 14
  • 44
  • 56