I am using the tm
package to clean up some data using the following code:
mycorpus <- Corpus(VectorSource(x))
mycorpus <- tm_map(mycorpus,
This is an alternative approach I've used in my own work with text analytics. Essentially, you refer to your document term matrix as a matrix when converting it into a data frame - after which you can run an additional line that makes your variable names R-friendly.
database <- as.data.frame(as.matrix(mycorpus))
colnames(database) <- make.names(colnames(database))
I'm not sure how (or if) this approach differs from the other answers in terms of output but I find this syntax much more straightforward and simpler to implement. Hope this helps!