dfm_sample | R Documentation |
Take a random sample of documents of the specified size from a dfm, with or without replacement, optionally by grouping variables or with probability weights.
dfm_sample(x, size = NULL, replace = FALSE, prob = NULL, by = NULL)
x |
the dfm object whose documents will be sampled |
size |
a positive number, the number of documents to select; when used
with |
replace |
if |
prob |
a vector of probability weights for obtaining the elements of the
vector being sampled. May not be applied when |
by |
optional grouping variable for sampling. This will be evaluated in
the docvars data.frame, so that docvars may be referred to by name without
quoting. This also changes previous behaviours for |
a dfm object (re)sampled on the documents, containing the document variables for the documents sampled.
sample
set.seed(10)
dfmat <- dfm(tokens(c("a b c c d", "a a c c d d d", "a b b c")))
dfmat
dfm_sample(dfmat)
dfm_sample(dfmat, replace = TRUE)
# by groups
dfmat <- dfm(tokens(data_corpus_inaugural[50:58]))
dfm_sample(dfmat, by = Party, size = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.