colRanks,dgCMatrix-method | R Documentation |
Calculates the rank of the elements for each row (column) of a matrix-like object.
## 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
)
x |
An NxK matrix-like object. |
rows , cols |
A |
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 |
There are three different methods available for handling ties:
for values with identical values the maximum rank is returned
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'.
for values with identical values the minimum rank is returned.
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.
matrixStats::rowRanks()
and
matrixStats::colRanks()
which are used
when the input is a matrix
or numeric
vector.
base::rank
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.