arrange() orders the rows of a data frame by the values of selected columns.

Unlike other dplyr verbs, arrange() largely ignores grouping; you need to explicitly mention grouping variables (or use .by_group = TRUE) in order to group by them, and functions of variables are evaluated once per data frame, not once per group.

# S3 method for SingleCellExperiment
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 of the same type as .data. The output has the following properties:

  • All rows appear in the output, but (usually) in a different place.

  • Columns are not modified.

  • Groups are not modified.

  • Data frame attributes are preserved.

Details

Missing values

Unlike base sorting with sort(), NA are:

  • always sorted to the end for local data, even when wrapped with desc().

  • treated differently for remote data, depending on the backend.

Methods

This function is a generic, which means that packages can provide implementations (methods) for other classes. See the documentation of individual methods for extra arguments and differences in behaviour.

The following methods are currently available in loaded packages: dbplyr (tbl_lazy), dplyr (data.frame), plotly (plotly), tidySingleCellExperiment (SingleCellExperiment) .

See also

Other single table verbs: mutate(), rename(), slice(), summarise()

Examples

data(pbmc_small)
pbmc_small |> 
    arrange(nFeature_RNA)
#> # A SingleCellExperiment-tibble abstraction: 80 × 17
#> # Features=230 | Cells=80 | Assays=counts, logcounts
#>    .cell orig.ident nCount_RNA nFeature_RNA RNA_snn_res.0.8 letter.idents groups
#>    <chr> <fct>           <dbl>        <int> <fct>           <fct>         <chr> 
#>  1 CATG… SeuratPro…         51           26 0               A             g2    
#>  2 GGCA… SeuratPro…        172           29 0               A             g1    
#>  3 AGTC… SeuratPro…        157           29 0               A             g1    
#>  4 GACG… SeuratPro…        202           30 0               A             g2    
#>  5 GGAA… SeuratPro…        150           30 0               A             g2    
#>  6 AGGT… SeuratPro…         62           31 0               A             g2    
#>  7 CTTC… SeuratPro…         41           32 0               A             g2    
#>  8 GTAA… SeuratPro…         67           33 0               A             g2    
#>  9 GTCA… SeuratPro…        210           33 0               A             g2    
#> 10 TGGT… SeuratPro…         64           36 0               A             g1    
#> # ℹ 70 more rows
#> # ℹ 10 more variables: RNA_snn_res.1 <fct>, file <chr>, ident <fct>,
#> #   PC_1 <dbl>, PC_2 <dbl>, PC_3 <dbl>, PC_4 <dbl>, PC_5 <dbl>, tSNE_1 <dbl>,
#> #   tSNE_2 <dbl>