ldaformat2dtm | R Documentation |
Data from the lda package is transformed to a document-term matrix. This data format can be used to fit topic models using package topicmodels.
Data in form of a document-term matrix is transformed to the LDA format used by package lda.
ldaformat2dtm(documents, vocab, omit_empty = TRUE)
dtm2ldaformat(x, omit_empty = TRUE)
documents |
A |
vocab |
A |
x |
An object of class |
omit_empty |
A logical indicating if empty documents should be removed when converting the objects. By default empty documents are removed. |
An object of class "DocumentTermMatrix"
is returned by
ldaformat2dtm()
and a list with components "documents"
and "vocab"
by dtm2ldaformat()
.
Bettina Gruen
if (require("lda")) {
data("cora.documents", package = "lda")
data("cora.vocab", package = "lda")
dtm <- ldaformat2dtm(cora.documents, cora.vocab)
cora <- dtm2ldaformat(dtm)
all.equal(cora, list(documents = cora.documents,
vocab = cora.vocab))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.