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]))
Run the code above in your browser using DataLab