colRanks-dgCMatrix-method: Calculates the rank of the elements for each row (column) of...

colRanks,dgCMatrix-methodR Documentation

Calculates the rank of the elements for each row (column) of a matrix-like object

Description

Calculates the rank of the elements for each row (column) of a matrix-like object.

Usage

## S4 method for signature 'dgCMatrix'
colRanks(
  x,
  rows = NULL,
  cols = NULL,
  ties.method = c("max", "average", "min"),
  preserveShape = FALSE,
  na.handling = c("keep", "last"),
  ...,
  useNames = TRUE
)

## S4 method for signature 'dgCMatrix'
rowRanks(
  x,
  rows = NULL,
  cols = NULL,
  ties.method = c("max", "average", "min"),
  preserveShape = TRUE,
  na.handling = c("keep", "last"),
  ...,
  useNames = TRUE
)

Arguments

x

An NxK matrix-like object.

rows, cols

A vector indicating the 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. Note that the default specifies fewer options than the original matrixStats package.

preserveShape

a boolean that specifies if the returned matrix has the same dimensions as the input matrix. By default this is true for 'rowRanks()', but false for 'colRanks()'.

na.handling

string specifying how 'NA's are handled. They can either be preserved with an 'NA' rank ('keep') or sorted in at the end ('last'). Default is 'keep' derived from the behavior of the equivalent

...

Additional arguments passed to specific methods.

useNames

If TRUE (default), names attributes of result are set. Else if FALSE, no naming support is done.

Details

There are three different methods available for handling ties:

'max'

for values with identical values the maximum rank is returned

'average'

for values with identical values the average of the ranks they cover is returned. Note, that in this case the return value is of type 'numeric'.

'min'

for values with identical values the minimum rank is returned.

Value

a matrix of type integer is returned unless ties.method = "average". Ithas dimensions' NxJ (KxJ) matrix, where N (K) is the number of rows (columns) of the input x.

See Also

  • matrixStats::rowRanks() and matrixStats::colRanks() which are used when the input is a matrix or numeric vector.

  • base::rank

Examples

mat <- matrix(rnorm(15), nrow = 5, ncol = 3)
mat[2, 1] <- NA
mat[3, 3] <- Inf
mat[4, 1] <- 0

print(mat)

rowRanks(mat)
colRanks(mat)

const-ae/sparseMatrixStats documentation built on June 15, 2024, 9:36 a.m.