
Slice Sample or Variable Information
slice_obs.Rd
Slice the sample or variable information tibble of an experiment()
.
These functions provide row-wise slicing operations similar to dplyr's slice functions. They select rows by position or based on values in specified columns, and update the expression matrix accordingly to match the new selection.
slice_obs()
andslice_var()
: Select rows by positionslice_head_obs()
andslice_head_var()
: Select first n rowsslice_tail_obs()
andslice_tail_var()
: Select last n rowsslice_sample_obs()
andslice_sample_var()
: Select random n rowsslice_max_obs()
andslice_max_var()
: Select rows with highest valuesslice_min_obs()
andslice_min_var()
: Select rows with lowest values
Usage
slice_obs(exp, ...)
slice_var(exp, ...)
slice_head_obs(exp, n, prop)
slice_head_var(exp, n, prop)
slice_tail_obs(exp, n, prop)
slice_tail_var(exp, n, prop)
slice_sample_obs(exp, n, prop, weight_by = NULL, replace = FALSE)
slice_sample_var(exp, n, prop, weight_by = NULL, replace = FALSE)
slice_max_obs(exp, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE)
slice_max_var(exp, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE)
slice_min_obs(exp, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE)
slice_min_var(exp, order_by, ..., n, prop, with_ties = TRUE, na_rm = FALSE)
Arguments
- exp
An
experiment()
.- ...
<
data-masking
> Forslice_*()
, integer row positions. Forslice_max()
andslice_min()
, variables to order by. Other arguments passed to the corresponding dplyr function.- n
For
slice_head()
,slice_tail()
,slice_sample()
,slice_max()
, andslice_min()
, the number of rows to select.- prop
For
slice_head()
,slice_tail()
,slice_sample()
,slice_max()
, andslice_min()
, the proportion of rows to select.- weight_by
For
slice_sample()
, sampling weights.- replace
For
slice_sample()
, should sampling be with replacement?- order_by
For
slice_max()
andslice_min()
, variable to order by.- with_ties
For
slice_max()
andslice_min()
, should ties be kept?- na_rm
For
slice_max()
andslice_min()
, should missing values be removed?
Value
A new experiment()
object.
Examples
# Create a toy experiment for demonstration
exp <- toy_experiment()
# Add columns needed for demonstration
exp$sample_info$score <- c(10, 20, 30, 15, 25, 35)
exp$var_info$value <- c(5, 10, 15, 8)
# Select specific rows by position
slice_obs(exp, 1, 3, 5)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 3 samples, 4 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value
# Select first 3 samples
slice_head_obs(exp, n = 3)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 3 samples, 4 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value
# Select last 2 variables
slice_tail_var(exp, n = 2)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 6 samples, 2 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value
# Select 2 random samples
slice_sample_obs(exp, n = 2)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 2 samples, 4 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value
# Select samples with highest scores
slice_max_obs(exp, order_by = score, n = 2)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 2 samples, 4 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value
# Select variables with lowest values
slice_min_var(exp, order_by = value, n = 2)
#>
#> ── Experiment ──────────────────────────────────────────────────────────────────
#> ℹ Expression matrix: 6 samples, 2 variables
#> ℹ Sample information fields: group, batch, and score
#> ℹ Variable information fields: protein, peptide, glycan_composition, and value