I want a function that does the opposite of max.col()
(which would be min.col)
There is an answer for this, but I don´t really understand it. Could anybody give a different solution?
CodePudding user response:
Negate the columns. Using BOD
which comes with R:
max.col(BOD)
## [1] 2 2 2 2 2 2
max.col(-BOD)
## [1] 1 1 1 1 1 1
If the data frame is not numeric use xtfrm
first
DF <- data.frame(X = c("a", "b", "a"), Y = c("b", "a", "b"))
max.col(-t(apply(DF, 1, xtfrm)))
## [1] 1 2 1