slice.corpus | R Documentation |
slice()
lets you index documents by their (integer) locations. It allows you
to select, remove, and duplicate documents. It is accompanied by a number of
helpers for common use cases:
slice_head()
and slice_tail()
select the first or last documents.
slice_sample()
randomly selects documents.
slice_min()
and slice_max()
select documents with highest or lowest values
of a document variable.
## S3 method for class 'corpus'
slice(.data, ..., .preserve = FALSE)
## S3 method for class 'corpus'
slice_head(.data, ..., n, prop)
## S3 method for class 'corpus'
slice_tail(.data, ..., n, prop)
## S3 method for class 'corpus'
slice_sample(.data, ..., n, prop, weight_by = NULL, replace = FALSE)
## S3 method for class 'corpus'
slice_min(.data, ..., n, prop, with_ties = TRUE)
## S3 method for class 'corpus'
slice_max(.data, ..., n, prop, with_ties = TRUE)
.data |
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details. |
... |
< |
.preserve |
Relevant when the |
n , prop |
Provide either If |
weight_by |
< |
replace |
Should sampling be performed with ( |
with_ties |
Should ties be kept together? The default, |
An object of the same type as .data
. The output has the following
properties:
Each document may appear 0, 1, or many times in the output. (If duplicated, then document names will be modified to remain unique.)
Document variables are not modified.
slice(data_corpus_inaugural, 2:5)
slice(data_corpus_inaugural, 55:n())
slice_head(data_corpus_inaugural, n = 2)
slice_tail(data_corpus_inaugural, n = 3)
slice_tail(data_corpus_inaugural, prop = .05)
set.seed(42)
slice_sample(data_corpus_inaugural, n = 3)
slice_sample(data_corpus_inaugural, prop = .10, replace = TRUE)
data_corpus_inaugural <- data_corpus_inaugural %>%
mutate(ntoks = ntoken(data_corpus_inaugural))
# shortest three texts
slice_min(data_corpus_inaugural, ntoks, n = 3)
# longest three texts
slice_max(data_corpus_inaugural, ntoks, n = 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.