Last chance! 50% off unlimited learning
Sale ends in
sample(x, size, replace = FALSE, prob = NULL, ...)
"sample"(x, size, replace = FALSE, prob = NULL, ...)
"sample"(x, size = ndoc(x), replace = FALSE, prob = NULL, ...)
"sample"(x, size = ndoc(x), replace = FALSE, prob = NULL, what = c("documents", "features"), ...)
sample
, which is not defined as a generic
method in the base package.documents
or
features
size
, drawn
from the corpus x
. The returned corpus object will contain all of
the meta-data of the original corpus, and the same document variables for
the documents selected.A dfm object with number of documents equal to size
, drawn
from the corpus x
. The returned corpus object will contain all of
the meta-data of the original corpus, and the same document variables for
the documents selected.
sample
# sampling from a corpus
summary(sample(inaugCorpus, 5))
summary(sample(inaugCorpus, 10, replace=TRUE))
# sampling from a dfm
myDfm <- dfm(inaugTexts[1:10], verbose = FALSE)
sample(myDfm)[, 1:10]
sample(myDfm, replace = TRUE)[, 1:10]
sample(myDfm, what = "features")[1:10, ]
Run the code above in your browser using DataLab