Subset to a specific number of samples.
# S3 method for rbiom
slice(.data, ..., .by = NULL, .preserve = FALSE, clone = TRUE)# S3 method for rbiom
slice_head(.data, n, prop, by = NULL, clone = TRUE, ...)
# S3 method for rbiom
slice_tail(.data, n, prop, by = NULL, clone = TRUE, ...)
# S3 method for rbiom
slice_min(
.data,
order_by,
n,
prop,
by = NULL,
with_ties = TRUE,
na_rm = FALSE,
clone = TRUE,
...
)
# S3 method for rbiom
slice_max(
.data,
order_by,
n,
prop,
by = NULL,
with_ties = TRUE,
na_rm = FALSE,
clone = TRUE,
...
)
# S3 method for rbiom
slice_sample(
.data,
n,
prop,
by = NULL,
weight_by = NULL,
replace = FALSE,
clone = TRUE,
...
)
An rbiom object.
An rbiom object, such as from as_rbiom()
.
For slice()
, integer row indexes. For other slice_*()
functions, not used. See dplyr::slice()
.
<tidy-select
> Optionally, a selection of columns to
group by for just this operation, functioning as an alternative to group_by()
. For
details and examples, see ?dplyr_by.
Relevant when the .data
input is grouped.
If .preserve = FALSE
(the default), the grouping structure
is recalculated based on the resulting data, otherwise the grouping is kept as is.
Create a copy of biom
before modifying. If FALSE
, biom
is modified in place as a side-effect. See speed ups for
use cases. Default: TRUE
Provide either n
, the number of rows, or prop
, the
proportion of rows to select. If neither are supplied, n = 1
will be
used. If n
is greater than the number of rows in the group
(or prop > 1
), the result will be silently truncated to the group size.
prop
will be rounded towards zero to generate an integer number of
rows.
A negative value of n
or prop
will be subtracted from the group
size. For example, n = -2
with a group of 5 rows will select 5 - 2 = 3
rows; prop = -0.25
with 8 rows will select 8 * (1 - 0.25) = 6 rows.
<data-masking
> Variable or
function of variables to order by. To order by multiple variables, wrap
them in a data frame or tibble.
Should ties be kept together? The default, TRUE
,
may return more rows than you request. Use FALSE
to ignore ties,
and return the first n
rows.
Should missing values in order_by
be removed from the result?
If FALSE
, NA
values are sorted to the end (like in arrange()
), so
they will only be included if there are insufficient non-missing values to
reach n
/prop
.
<data-masking
> Sampling
weights. This must evaluate to a vector of non-negative numbers the same
length as the input. Weights are automatically standardised to sum to 1.
Should sampling be performed with (TRUE
) or without
(FALSE
, the default) replacement.
library(rbiom)
# The last 3 samples in the metadata table.
biom <- slice_tail(hmp50, n = 3)
biom$metadata
# The 3 oldest subjects sampled.
biom <- slice_max(hmp50, Age, n = 3)
biom$metadata
# Pick 3 samples at random.
biom <- slice_sample(hmp50, n = 3)
biom$metadata
Run the code above in your browser using DataLab