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

Description Usage Arguments Details Value See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## S4 method for signature 'dgCMatrix'
colRanks(
  x,
  rows = NULL,
  cols = NULL,
  ties.method = c("max", "average", "min"),
  preserveShape = FALSE,
  na.handling = c("keep", "last")
)

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

Arguments

x

An NxK matrix-like object.

rows

A vector indicating the subset of rows (and/or columns) to operate over. If NULL, no subsetting is done.

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

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

Examples

1
2
3
4
5
6
7
8
9
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)

sparseMatrixStats documentation built on Feb. 4, 2021, 2 a.m.