Row-wise maxima

row_max(.data, which = NULL, ...)

# S3 method for matrix
row_max(.data, which = NULL, ...)

# S3 method for data.frame
row_max(.data, which = NULL, ...)

Arguments

.data

A two-dimensional data structure.

which

If not NULL, one of ("first", "last") to return the index where maxima occurs.

...

Arguments passed on to op_ctrl

output_class

One of ("vector", "list", "data.frame", "matrix"), possibly abbreviated.

na_action

One of ("exclude", "pass"), possibly abbreviated. See stats::na.pass for semantics.

cols

A vector indicating which columns to consider for the operation. If NULL, all columns are used. If its length is 0, no columns are considered. Negative numbers, logical values, character vectors representing column names, and tidyselect::select_helpers are supported.

rows

Like cols but for row indices, and without tidyselect support.

factor_mode

One of ("character", "integer"), possibly abbreviated. If a column is a factor, this determines whether the operation uses its internal integer values, or the character values from its levels.

Details

For data frames, if the input columns have different modes, all of them will be promoted on-the-fly to the highest one in the R hierarchy.

Note

String comparison is done in C++, which can vary from what R does.

Examples

df <- data.frame(FALSE, TRUE, NA_character_) # all columns promoted to character (on-the-fly) row_max(df)
#> [1] "TRUE"
row_max(df, na_action = "pass")
#> [1] NA
# no promotion row_max(df, cols = 1:2)
#> [1] TRUE
row_max(df, cols = 1:2, which = "first")
#> [1] 2