Learn R Programming

quanteda (version 1.1.1)

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,
  margin = 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.

margin

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
# 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