maxCol: Column or row indices of maximum values

View source: R/utils.R

maxColR Documentation

Column or row indices of maximum values

Description

Find column or row indices of maximum values in matrices. Works in a similar way as base::max.col() but without conversion of sparse matrices to dense matrices.

Usage

maxCol(x, ties_method = c("random", "first", "last"), use_nan = FALSE)

maxRow(x, ties_method = c("random", "first", "last"), use_nan = FALSE)

Arguments

x

a base::matrix or Matrix::Matrix object.

ties_method

specify how to handle ties. If "random", choose an index randomly within the ties; if "first" or "last" returns the index of the first or the last tie elements, respectively.

use_nan

if TRUE, return NA for columns or rows with all zero. Applies only when x is a sparse matrix.

Value

an integer vector

Examples

mt <- Matrix::rsparsematrix(100, 100, 0.9)
maxCol(mt, ties_method = "first")
max.col(mt, ties.method = "first") # the same

proxyC documentation built on Oct. 30, 2026, 9:08 a.m.