get_max_colname_per_row | R Documentation |
This function takes a numeric matrix as input and returns a named vector where each element
corresponds to a row of the matrix. The names of the vector are the row names of the matrix,
and the values are the column names where the maximum value of each row is found. If there are
multiple columns with the maximum value in a row, the value for that row will be set to
multi_max_str
. If na.remove
is set to TRUE
, NA values will be removed before finding the
maximum value.
get_max_colname_per_row(
mat,
na.remove = TRUE,
collapse = "-",
verbose = TRUE,
multi_max_str = "multiple.maxima",
suffix = "rows have multiple maxima."
)
mat |
A numeric matrix |
na.remove |
Logical. Should NA values be removed before finding the maximum value? Default: TRUE |
collapse |
Character. The character to use to collapse multiple column names into a single string. Default: "-" |
verbose |
Logical. Should messages be printed to the console? Default: TRUE |
multi_max_str |
Character. The string to use when multiple columns have the maximum value. Default: "multiple.maxima" |
suffix |
Character. The suffix to add to the |
mat <- matrix(data = c(1, 2, 3, 9, 5, 6), nrow = 2, ncol = 3, byrow = TRUE)
colnames(mat) <- c("UVI1", "UVI2", "UVI3")
rownames(mat) <- c("Cell1", "Cell2")
mat
get_max_colname_per_row(mat)
mat[5] <- NA
mat[2] <- NaN
mat[1] <- 2
mat
get_max_colname_per_row(mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.