O'Reilly logo
  • Charles Weiss thinks this is interesting:

sms_dtm <- DocumentTermMatrix(corpus_clean)


Cover of Machine Learning with R


If you get the error message "Error: inherits(doc, "TextDocument") is not TRUE" then you must run the following command first:

corpus_clean <- tm_map(corpus_clean, PlainTextDocument)

The "tolower" function does not return a plain text document, which is required for the DocumentTermMatrix function to execute properly. The above function converts the corpus to plain text