| dfm_match | R Documentation |
Match the columns of multiple dfm objects using a character vector.
dfm_match(x, features, verbose = quanteda_options("verbose"))
x |
the dfm object. |
features |
character vector for the feature names to be matched in the
resulting dfm. Columns not included in |
verbose |
if |
Matching the dfm columns is necessary when you split a corpus into two: you fit
a model on the test set and evaluation it on the test set whose features must be
identical. It is also used in bootstrap_dfm().
A dfm whose features are identical to those specified in
features.
Unlike dfm_select(), this function will add feature names
not already present in x. It also provides only fixed,
case-sensitive matches. For more flexible feature selection, see
dfm_select().
dfm_select()
# matching a dfm to a feature vector
dfm_match(dfm(tokens("")), letters[1:5])
dfm_match(data_dfm_lbgexample, c("A", "B", "Z"))
dfm_match(data_dfm_lbgexample, c("B", "newfeat1", "A", "newfeat2"))
# matching one dfm to another
txt <- c("This is text one", "The text two", "This is text three")
(dfmt1 <- dfm(tokens(txt[1:2])))
(dfmt2 <- dfm(tokens(txt[2:3])))
(dfmt3 <- dfm(dfm_match(dfmt1, featnames(dfmt2))))
identical(featnames(dfmt2), featnames(dfmt3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.