Sample randomly from a dfm object, from documents or features.
dfm_sample( x, size = ifelse(margin == "documents", ndoc(x), nfeat(x)), replace = FALSE, prob = NULL, margin = c("documents", "features") )
x | the dfm object whose documents or features will be sampled |
---|---|
size | a positive number, the number of documents or features to select.
The default is the number of documents or the number of features, for
|
replace | logical; should sampling be with replacement? |
prob | a vector of probability weights for obtaining the elements of the vector being sampled. |
margin | dimension (of a dfm) to sample: can be |
A dfm object with number of documents or features equal to size
, drawn
from the dfm x
.
#> Document-feature matrix of: 2 documents, 4 features (12.5% sparse). #> features #> docs a b c d #> text1 1 1 2 1 #> text2 2 0 2 3#> Document-feature matrix of: 2 documents, 4 features (12.5% sparse). #> features #> docs a b c d #> text1 1 1 2 1 #> text2 2 0 2 3#> Document-feature matrix of: 2 documents, 4 features (25.0% sparse). #> features #> docs a b c d #> text2.1 2 0 2 3 #> text2.2 2 0 2 3#> Document-feature matrix of: 2 documents, 4 features (12.5% sparse). #> features #> docs d c b a #> text1 1 2 1 1 #> text2 3 2 0 2#> Document-feature matrix of: 2 documents, 4 features (0.0% sparse). #> features #> docs c c c d #> text1 2 2 2 1 #> text2 2 2 2 3