colRanks {DelayedMatrixStats} | R Documentation

## Gets the rank of each row (column) of a matrix

### Description

Gets the rank of each row (column) of a matrix.

### Usage

    colRanks(x, rows = NULL, cols = NULL, ties.method = c("max", "average",
      "min"), dim. = dim(x), preserveShape = FALSE, ...)

    rowRanks(x, rows = NULL, cols = NULL, ties.method = c("max", "average",
      "min"), dim. = dim(x), ...)

    ## S4 method for signature 'DelayedMatrix'
    colRanks(x, rows = NULL, cols = NULL,
      ties.method = c("max", "average", "min"), dim. = dim(x),
      preserveShape = FALSE, force_block_processing = FALSE, ...)

    ## S4 method for signature 'DelayedMatrix'
    rowRanks(x, rows = NULL, cols = NULL,
      ties.method = c("max", "average", "min"), dim. = dim(x),
      force_block_processing = FALSE, ...)

### Arguments

`x` | A NxK DelayedMatrix.
`rows` | A `vector` indicating subset of rows (and/or columns) to operate over. If `NULL`, no subsetting is done.
`cols` | A `vector` indicating subset of rows (and/or columns) to operate over. If `NULL`, no subsetting is done.
`ties.method` | A `character` string specifying how ties are treated. For details, see below.
`dim.` | An `integer` `vector` of length two specifying the dimension of `x`, also when not a `matrix`.
`preserveShape` | A `logical` specifying whether the `matrix` returned should preserve the input shape of `x`, or not.
`...` | Additional arguments passed to specific methods.
`force_block_processing` | `FALSE` (the default) means that a seed-aware, optimised method is used (if available). This can be overridden to use the general block-processing strategy by setting this to `TRUE` (typically not advised). The block-processing strategy loads one or more (depending on `getOption("DelayedArray.block.size")`) columns (`colFoo()`) or rows (`rowFoo()`) into memory as an ordinary base::array.

### Details

The row ranks of `x` are collected as rows of the result matrix.

The column ranks of `x` are collected as rows if `preserveShape = FALSE`, otherwise as columns.

The implementation is optimized for both speed and memory. To avoid coercing to `double`s (and hence memory allocation), there is a unique implementation for `integer` matrices. It is more memory efficient to do `colRanks(x, preserveShape = TRUE)` than `t(colRanks(x, preserveShape = FALSE))`.

Any `names` of `x` are ignored and absent in the result.

### Value

An `integer` `matrix` is returned. The `rowRanks()` function always returns an NxK `matrix`, where N (K) is the number of rows (columns) whose ranks are calculated.

The `colRanks()` function returns an NxK `matrix`, if `preserveShape = TRUE`, otherwise a KxN `matrix`.

%% The mode of the returned matrix is `integer`, except for %% `ties.method == "average"` when it is `double`.

### Missing and non- values

These are ranked as `NA`, as with `na.last = "keep"` in the `rank`() function.

### See Also

`rank`(). For developers, see also Section 'Utility functions' in 'Writing R Extensions manual', particularly the native functions `R_qsort_I()` and `R_qsort_int_I()`.

### Examples

    # A DelayedMatrix with a 'Matrix' seed
    dm_Matrix <- DelayedArray(Matrix::Matrix(c(rep(1L, 5),
                                               as.integer((0:4) ^ 2),
                                               seq(-5L, -1L, 1L)),
                                             ncol = 3))

    colRanks(dm_Matrix)

    rowRanks(dm_Matrix)

[Package DelayedMatrixStats version 1.0.3 Index]