powered by
Sample randomly from a dfm object, from documents or features.
dfm_sample(x, size = ndoc(x), replace = FALSE, prob = NULL, what = c("documents", "features"))
the dfm object whose documents or features will be sampled
a positive number, the number of documents or features to select
logical; should sampling be with replacement?
a vector of probability weights for obtaining the elements of the vector being sampled.
dimension (of a dfm) to sample: can be documents or features
documents
features
A dfm object with number of documents or features equal to size, drawn from the dfm x.
size
x
sample
# NOT RUN { myDfm <- dfm(data_corpus_inaugural[1:10]) dfm_sample(myDfm)[, 1:10] dfm_sample(myDfm, replace = TRUE)[, 1:10] dfm_sample(myDfm, what = "features")[1:10, ] # }
Run the code above in your browser using DataLab