Learn R Programming

BBmisc (version 1.13)

getMaxIndexOfRows: Find row- or columnwise the index of the maximal / minimal element in a matrix.

Description

getMaxIndexOfRows returns the index of the maximal element of each row. getMinIndexOfRows returns the index of the minimal element of each row. getMaxIndexOfCols returns the index of the maximal element of each col. getMinIndexOfCols returns the index of the minimal element of each col. If a corresponding vector (row or col) is empty, possibly after NA removal, -1 is returned as index.

Usage

getMaxIndexOfRows(x, weights = NULL, ties.method = "random", na.rm = FALSE)

getMinIndexOfRows(x, weights = NULL, ties.method = "random", na.rm = FALSE)

getMaxIndexOfCols(x, weights = NULL, ties.method = "random", na.rm = FALSE)

getMinIndexOfCols(x, weights = NULL, ties.method = "random", na.rm = FALSE)

Value

[integer(n)].

Arguments

x

[matrix(n,m)]
Numerical input matrix.

weights

[numeric]
Weights (same length as number of rows/cols). If these are specified, the index is selected from the weighted elements (see getMaxIndex). Default is NULL which means no weights.

ties.method

[character(1)]
How should ties be handled? Possible are: “random”, “first”, “last”. Default is “random”.

na.rm

[logical(1)]
If FALSE, NA is returned if an NA is encountered in x. If TRUE, NAs are disregarded. Default is FALSE

Examples

Run this code
x = matrix(runif(5 * 3), ncol = 3)
print(x)
print(getMaxIndexOfRows(x))
print(getMinIndexOfRows(x))

Run the code above in your browser using DataLab