Learn R Programming

quanteda (version 0.9.9-50)

dfm_sample: randomly sample documents or features from a dfm

Description

Sample randomly from a dfm object, from documents or features.

Usage

dfm_sample(x, size = ndoc(x), replace = FALSE, prob = NULL,
  what = c("documents", "features"))

Arguments

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.
what
dimension (of a dfm) to sample: can be documents or features

Value

A dfm object with number of documents or features equal to size, drawn from the dfm x.

See Also

sample

Examples

Run this code
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