Skip to contents

arrange() orders either the rows or columns of a SummarizedExperiment object. Note, to guarentee a valid SummarizedExperiment is returned, arranging in the assays evaluation context is disabled.

Unlike other dplyr verbs, arrange() largely ignores grouping. The SummarizedExperiment method also provides the same functionality via the .by_group argument.

Usage

# S3 method for class 'SummarizedExperiment'
arrange(.data, ..., .by_group = FALSE)

Arguments

.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.

...

<data-masking> Variables, or functions of variables. Use desc() to sort a variable in descending order.

.by_group

If TRUE, will sort first by grouping variable. Applies to grouped data frames only.

Value

an object inheriting SummarizedExperiment class

Examples


#arrange within rows/cols contexts separately
arrange(se_simple,
        rows(direction),
        cols(dplyr::desc(condition)))
#> class: SummarizedExperiment 
#> dim: 5 4 
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(5): row_2 row_3 row_5 row_1 row_4
#> rowData names(3): gene length direction
#> colnames(4): col_3 col_4 col_1 col_2
#> colData names(2): sample condition

# access assay data to compute arrangement
arrange(se_simple, 
        rows(rowSums(.assays_asis$counts)),
        cols(colSums(.assays_asis$counts)))
#> class: SummarizedExperiment 
#> dim: 5 4 
#> metadata(0):
#> assays(2): counts logcounts
#> rownames(5): row_2 row_1 row_4 row_5 row_3
#> rowData names(3): gene length direction
#> colnames(4): col_4 col_3 col_2 col_1
#> colData names(2): sample condition

# assay context is disabled
arrange(se_simple, counts) |> try()
#> Error in arrange(se_simple, counts) : Cannot arrange in `assays` context
#>  review expression indices 1 in dots
#>  consider wrapping expressions in rows(...) or cols(...)

# convert to `data.frame` first
as.data.frame(se_simple) |>
  arrange(counts)
#>    .features .samples counts logcounts gene length direction sample condition
#> 1      row_2    col_3      1 0.0000000   g2     24         +     s3      drug
#> 2      row_2    col_2      2 0.6931472   g2     24         +     s2     cntrl
#> 3      row_4    col_4      3 1.0986123   g4     39         -     s4      drug
#> 4      row_2    col_4      4 1.3862944   g2     24         +     s4      drug
#> 5      row_5    col_4      5 1.6094379   g5     37         +     s4      drug
#> 6      row_3    col_2      6 1.7917595   g3     60         +     s2     cntrl
#> 7      row_1    col_3      7 1.9459101   g1      1         -     s3      drug
#> 8      row_1    col_2      8 2.0794415   g1      1         -     s2     cntrl
#> 9      row_1    col_4      9 2.1972246   g1      1         -     s4      drug
#> 10     row_4    col_3     10 2.3025851   g4     39         -     s3      drug
#> 11     row_4    col_1     11 2.3978953   g4     39         -     s1     cntrl
#> 12     row_5    col_3     12 2.4849066   g5     37         +     s3      drug
#> 13     row_5    col_2     13 2.5649494   g5     37         +     s2     cntrl
#> 14     row_1    col_1     14 2.6390573   g1      1         -     s1     cntrl
#> 15     row_3    col_3     15 2.7080502   g3     60         +     s3      drug
#> 16     row_3    col_1     16 2.7725887   g3     60         +     s1     cntrl
#> 17     row_4    col_2     17 2.8332133   g4     39         -     s2     cntrl
#> 18     row_5    col_1     18 2.8903718   g5     37         +     s1     cntrl
#> 19     row_2    col_1     19 2.9444390   g2     24         +     s1     cntrl
#> 20     row_3    col_4     20 2.9957323   g3     60         +     s4      drug