Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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, ties.method = "random", na.rm = FALSE)

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

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

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

Arguments

x

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

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

Value

[integer(n)].

Examples

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

BBmisc

Miscellaneous Helper Functions for B. Bischl

v1.11
BSD_2_clause + file LICENSE
Authors
Bernd Bischl [aut, cre], Michel Lang [aut], Jakob Bossek [aut], Daniel Horn [aut], Jakob Richter [aut], Dirk Surmann [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.