R/DTMFromCorpus.R

Defines functions DTMFromCorpus

Documented in DTMFromCorpus

DTMFromCorpus <-
function(corpus, rowNames) {
  dtm <- tm::DocumentTermMatrix(corpus, control = list(weighting = tm::weightBin, removePunctuation = FALSE))
  dtm <- as.matrix(dtm)
  if(missing(rowNames)) {
    row.names(dtm) <- paste0("A", 1:nrow(dtm))
  } else {
    row.names(dtm) <- rowNames
  }
  dtm <- dtm[which(rowSums(dtm) != 0), ]
  
  return(dtm)
}

Try the KDViz package in your browser

Any scripts or data that you put into this service are public.

KDViz documentation built on May 1, 2019, 6:34 p.m.