"Compresses" or groups a dfm or fcm whose dimension names are
the same, for either documents or features. This may happen, for instance,
if features are made equivalent through application of a thesaurus. It could also be needed after a
rbind.dfm operation. In most cases, you will not
need to call 'dfm_compress', since it is called automatically by functions that change the
dimensions of the dfm, e.g.
1 2 3
input object, a dfm or fcm
character indicating on which margin to compress a dfm, either
additional arguments passed from generic to specific methods
dfm_compress returns a dfm whose dimensions have been
recombined by summing the cells across identical dimension names
(docnames or featnames). The docvars will be
preserved for combining by features but not when documents are combined.
fcm_compress returns an fcm whose features have been
recombined by combining counts of identical features, summing their counts.
fcm_compress works only when the fcm was created with a
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# dfm_compress examples dfmat <- rbind(dfm(c("b A A", "C C a b B"), tolower = FALSE), dfm("A C C C C C", tolower = FALSE)) colnames(dfmat) <- char_tolower(featnames(dfmat)) dfmat dfm_compress(dfmat, margin = "documents") dfm_compress(dfmat, margin = "features") dfm_compress(dfmat) # no effect if no compression needed dfmatsubset <- dfm(data_corpus_inaugural[1:5]) dim(dfmatsubset) dim(dfm_compress(dfmatsubset)) # compress an fcm fcmat1 <- fcm(tokens("A D a C E a d F e B A C E D"), context = "window", window = 3) ## this will produce an error: # fcm_compress(fcmat1) txt <- c("The fox JUMPED over the dog.", "The dog jumped over the fox.") toks <- tokens(txt, remove_punct = TRUE) fcmat2 <- fcm(toks, context = "document") colnames(fcmat2) <- rownames(fcmat2) <- tolower(colnames(fcmat2)) colnames(fcmat2) <- rownames(fcmat2) <- "fox" fcmat2 fcm_compress(fcmat2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.