Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

convert-wrappers

Convenience wrappers for dfm convert


Description

To make the usage as consistent as possible with other packages, quanteda also provides shortcut wrappers to convert(), designed to be similar in syntax to analogous commands in the packages to whose format they are converting.

Usage

dfm2austin(x)

dfm2tm(x, weighting = tm::weightTf)

dfm2lda(x, omit_empty = TRUE)

dtm2lda(x, omit_empty = TRUE)

dfm2dtm(x, omit_empty = TRUE)

dfm2stm(x, docvars = NULL, omit_empty = TRUE)

Arguments

x

the dfm to be converted

weighting

a tm weight, see tm::weightTf()

omit_empty

logical; if TRUE, omit empty documents and features from the converted dfm. This is required for some formats (such as STM) that do not accept empty documents. Only used when to = "lda" or to = "topicmodels". For to = "stm" format, omit_empty`` is always TRUE'.

docvars

optional data.frame of document variables used as the meta information in conversion to the stm package format. This aids in selecting the document variables only corresponding to the documents with non-zero counts. Only affects the "stm" format.

...

additional arguments used only by as.DocumentTermMatrix

Details

dfm2lda provides converts a dfm into the list representation of terms in documents used by the lda package (a list with components "documents" and "vocab" as needed by lda::lda.collapsed.gibbs.sampler()).

dfm2ldaformat provides converts a dfm into the list representation of terms in documents used by the lda package (a list with components "documents" and "vocab" as needed by lda::lda.collapsed.gibbs.sampler()).

Value

A converted object determined by the value of to (see above). See conversion target package documentation for more detailed descriptions of the return formats.

Note

Additional coercion methods to base R objects are also available:

[as.data.frame](x)

converts a dfm into a data.frame

[as.matrix](x)

converts a dfm into a matrix

Examples

dfmat <- corpus_subset(data_corpus_inaugural, Year > 1970) %>%
    tokens() %>%
    dfm()

## Not run: 
# shortcut conversion to lda package list format
identical(quanteda:::dfm2lda(dfmat), convert(dfmat, to = "lda"))

## End(Not run)

## Not run: 
# shortcut conversion to lda package list format
identical(dfm2ldaformat(dfmat), convert(dfmat, to = "lda"))

## End(Not run)

quanteda

Quantitative Analysis of Textual Data

v3.0.0
GPL-3
Authors
Kenneth Benoit [cre, aut, cph] (<https://orcid.org/0000-0002-0797-564X>), Kohei Watanabe [aut] (<https://orcid.org/0000-0001-6519-5265>), Haiyan Wang [aut] (<https://orcid.org/0000-0003-4992-4311>), Paul Nulty [aut] (<https://orcid.org/0000-0002-7214-4666>), Adam Obeng [aut] (<https://orcid.org/0000-0002-2906-4775>), Stefan Müller [aut] (<https://orcid.org/0000-0002-6315-4125>), Akitaka Matsuo [aut] (<https://orcid.org/0000-0002-3323-6330>), William Lowe [aut] (<https://orcid.org/0000-0002-1549-6163>), Christian Müller [ctb], European Research Council [fnd] (ERC-2011-StG 283794-QUANTESS)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.