powered by
Sample randomly from a dfm object, from documents or features.
dfm_sample(x, size = ndoc(x), replace = FALSE, prob = NULL, margin = 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 { set.seed(10) myDfm <- dfm(data_corpus_inaugural[1:10]) head(myDfm) head(dfm_sample(myDfm)) head(dfm_sample(myDfm, replace = TRUE)) head(dfm_sample(myDfm, margin = "features")) # }
Run the code above in your browser using DataLab