
Arrange Sample or Variable Information
arrange_obs.Rd
Arrange the sample or variable information tibble of an experiment()
.
The same syntax as dplyr::arrange()
is used.
For example, to arrange samples by the "group" column,
use arrange_obs(exp, group)
.
This actually calls dplyr::arrange()
on the sample information tibble
with the group
column,
and then updates the expression matrix accordingly to match the new order.
Arguments
- exp
An
experiment()
.- ...
<
data-masking
> Variables to arrange by, passed todplyr::arrange()
internally.
Value
An new experiment()
object.
Examples
# Create a toy experiment for demonstration
exp <- toy_experiment()
# Add a type column to the variable information for demonstration
exp$var_info$type <- c("Y", "X", "Z", "Y")
# Arrange samples by group column
arranged_exp <- arrange_obs(exp, group)
arranged_exp$sample_info
#> # A tibble: 6 × 3
#> sample group batch
#> <chr> <chr> <dbl>
#> 1 S1 A 1
#> 2 S2 A 2
#> 3 S3 A 1
#> 4 S4 B 2
#> 5 S5 B 1
#> 6 S6 B 2
arranged_exp$expr_mat
#> S1 S2 S3 S4 S5 S6
#> V1 1 5 9 13 17 21
#> V2 2 6 10 14 18 22
#> V3 3 7 11 15 19 23
#> V4 4 8 12 16 20 24
# Arrange variables by type column
arranged_exp <- arrange_var(exp, type)
arranged_exp$var_info
#> # A tibble: 4 × 5
#> variable protein peptide glycan_composition type
#> <chr> <chr> <chr> <chr> <chr>
#> 1 V2 PRO2 PEP2 H5N2 X
#> 2 V1 PRO1 PEP1 H5N2 Y
#> 3 V4 PRO3 PEP4 N3N2 Y
#> 4 V3 PRO3 PEP3 N3N2 Z
arranged_exp$expr_mat
#> S1 S2 S3 S4 S5 S6
#> V2 2 6 10 14 18 22
#> V1 1 5 9 13 17 21
#> V4 4 8 12 16 20 24
#> V3 3 7 11 15 19 23
# Arrange by multiple columns
arrange_obs(exp, group, sample)$sample_info
#> # A tibble: 6 × 3
#> sample group batch
#> <chr> <chr> <dbl>
#> 1 S1 A 1
#> 2 S2 A 2
#> 3 S3 A 1
#> 4 S4 B 2
#> 5 S5 B 1
#> 6 S6 B 2