-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_max_colname_per_row.Rd
52 lines (46 loc) · 1.75 KB
/
get_max_colname_per_row.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/CodeAndRoll2.R
\name{get_max_colname_per_row}
\alias{get_max_colname_per_row}
\title{Get the Column Name corresponding to the Maximum Value in each Row (handles ambiguous matches)}
\usage{
get_max_colname_per_row(
mat,
na.remove = TRUE,
collapse = "-",
verbose = TRUE,
multi_max_str = "multiple.maxima",
suffix = "rows have multiple maxima."
)
}
\arguments{
\item{mat}{A numeric matrix}
\item{na.remove}{Logical. Should NA values be removed before finding the maximum value?
Default: TRUE}
\item{collapse}{Character. The character to use to collapse multiple column names into a single
string. Default: "-"}
\item{verbose}{Logical. Should messages be printed to the console? Default: TRUE}
\item{multi_max_str}{Character. The string to use when multiple columns have the maximum value.
Default: "multiple.maxima"}
\item{suffix}{Character. The suffix to add to the \code{multi_max_str} string. Default: "rows have}
}
\description{
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
\code{multi_max_str}. If \code{na.remove} is set to \code{TRUE}, NA values will be removed before finding the
maximum value.
}
\examples{
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)
}