output_dtm {chinese.misc}R Documentation

Convert or Write DTM/TDM Object Quickly

Description

Given a TermDocumentMatrix or DocumentTermMatrix object, the function converts it to a matrix or write it into a .csv file, with additional filenames attached to it.

Usage

output_dtm(x, outputfile = NULL, doc_name = NULL)

Arguments

x

an object created by tm::TermDocumentMatrix or tm::DocumentTermMatrix.

outputfile

when it is NULL (default), no file is written and a matrix is returned. When a filename is provided, it will write the matrix into a file. The filename must end with ".csv".

doc_name

whether NULL or a character vector specifying the names you want to give to texts. If it is not a character vector, the function will try to coerce. Then the names become the row names of the returned matrix. Double inversed slashes will be converted to "/" by the function. The length of the argument must be equal to the number of files. NA element is not allowed. By default it is NULL, which means no name is added.

Examples

require(tm)
x <- c(
  "Hello, what do you want to drink?", 
  "drink a bottle of milk", 
  "drink a cup of coffee", 
  "drink some water")
dtm <- corp_or_dtm(x, from = "v", type = "dtm")
output_dtm(dtm, doc_name = paste("doc", 1:4))

[Package chinese.misc version 0.2.3 Index]