dfm_sample: Randomly sample documents or features from a dfm

Description Usage Arguments Value See Also Examples

View source: R/dfm_sample.R

Description

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

Usage

1
2
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

1
2
3
4
5
6
set.seed(10)
dfmat <- dfm(data_corpus_inaugural[1:10])
head(dfmat)
head(dfm_sample(dfmat))
head(dfm_sample(dfmat, replace = TRUE))
head(dfm_sample(dfmat, margin = "features"))

quanteda/quanteda documentation built on Feb. 16, 2019, 5:45 a.m.