TermDocumentMatrix
From tm v0.6-2
by Ingo Feinerer
Term-Document Matrix
Constructs or coerces to a term-document matrix or a document-term matrix.
Usage
TermDocumentMatrix(x, control = list())
DocumentTermMatrix(x, control = list())
as.TermDocumentMatrix(x, ...)
as.DocumentTermMatrix(x, ...)
Arguments
- x
- a corpus for the constructors and either a term-document
matrix or a document-term matrix or a simple
triplet matrix (package
slam ) or a - control
- a named list of control options. There are local
options which are evaluated for each document and global options
which are evaluated once for the constructed matrix. Available local
options are documented in
- ...
- the additional argument
weighting
(typically aWeightFunction
) is allowed when coercing a simple triplet matrix to a term-document or document-term matrix.
Value
- An object of class
TermDocumentMatrix
or classDocumentTermMatrix
(both inheriting from a simple triplet matrix in packageslam ) containing a sparse term-document matrix or document-term matrix. The attributeWeighting
contains the weighting applied to the matrix.
See Also
termFreq
for available local control options.
Examples
data("crude")
tdm <- TermDocumentMatrix(crude,
control = list(removePunctuation = TRUE,
stopwords = TRUE))
dtm <- DocumentTermMatrix(crude,
control = list(weighting =
function(x)
weightTfIdf(x, normalize =
FALSE),
stopwords = TRUE))
inspect(tdm[202:205, 1:5])
inspect(tdm[c("price", "texas"), c("127", "144", "191", "194")])
inspect(dtm[1:5, 273:276])
Community examples
Looks like there are no examples yet.