dfm_sample.Rd
Sample randomly from a dfm object, from documents or features.
dfm_sample(x, size = ndoc(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 |
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: 6 documents, 3,366 features (82.7% sparse).#> Document-feature matrix of: 6 documents, 3,366 features (82.7% sparse).#> Document-feature matrix of: 6 documents, 3,366 features (84.5% sparse).#> Document-feature matrix of: 6 documents, 10 features (90.0% sparse). #> 6 x 10 sparse Matrix of class "dfm" #> features #> docs reciprocated savage accomplishing anxious representative vows #> 1789-Washington 0 0 0 0 0 0 #> 1793-Washington 0 0 0 0 0 0 #> 1797-Adams 0 0 0 0 0 0 #> 1801-Jefferson 0 0 0 1 1 0 #> 1805-Jefferson 0 0 0 0 0 0 #> 1809-Madison 0 1 0 0 0 0 #> features #> docs observed situation enhance approach #> 1789-Washington 0 0 0 0 #> 1793-Washington 0 0 0 0 #> 1797-Adams 0 1 0 0 #> 1801-Jefferson 0 0 0 1 #> 1805-Jefferson 0 0 0 0 #> 1809-Madison 0 1 0 0