Skip to content

Instantly share code, notes, and snippets.

@zunman
Created September 11, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zunman/e253ea6dc5fddce771b9da538c019578 to your computer and use it in GitHub Desktop.
Save zunman/e253ea6dc5fddce771b9da538c019578 to your computer and use it in GitHub Desktop.
# Create the Document-Term matrix
DTM <- DocumentTermMatrix(MyCorpus, control = list(bounds = list(global = c(0, Inf))))
dim(DTM)
# Create a sparse matrix to put into SVM
sparse_DTM <- sparseMatrix(i = DTM$i, j = DTM$j, x = DTM$v,
dims = dim(DTM),
dimnames = list(rownames(DTM), colnames(DTM)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment