dfm_group | R Documentation |
Combine documents in a dfm by a grouping variable, by summing the cell frequencies within group and creating new "documents" with the group labels.
dfm_group(x, groups = docid(x), fill = FALSE, force = FALSE)
x |
a dfm |
groups |
grouping variable for sampling, equal in length to the number
of documents. This will be evaluated in the docvars data.frame, so that
docvars may be referred to by name without quoting. This also changes
previous behaviours for |
fill |
logical; if |
force |
logical; if |
dfm_group
returns a dfm whose documents are equal to
the unique group combinations, and whose cell values are the sums of the
previous values summed by group. Document-level variables that have no
variation within groups are saved in docvars. Document-level
variables that are lists are dropped from grouping, even when these exhibit
no variation within groups.
corp <- corpus(c("a a b", "a b c c", "a c d d", "a c c d"),
docvars = data.frame(grp = c("grp1", "grp1", "grp2", "grp2")))
dfmat <- dfm(tokens(corp))
dfm_group(dfmat, groups = grp)
dfm_group(dfmat, groups = c(1, 1, 2, 2))
# with fill = TRUE
dfm_group(dfmat, fill = TRUE,
groups = factor(c("A", "A", "B", "C"), levels = LETTERS[1:4]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.