Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the opposite function of max.col (R language)

Tags:

r

What is the opposite function of max.col (R language).

I couldn't find min.col or relevant info in the manual:

https://stat.ethz.ch/R-manual/R-devel/library/base/html/maxCol.html

I'm trying to generate an opposite function of this:

cols = which(names(df) %in% c( "avp", "USD.KRW","cd")); 
df$max_col = names(df)[cols][max.col(df[cols])]
like image 259
Renaissance Avatar asked Feb 17 '19 06:02

Renaissance


Video Answer


1 Answers

You can use

min.col <- function(m, ...) max.col(-m, ...)

Used in formal optimization (where many tools prefer to find a minimum of a function), the opposite of a maximal number is the minimal negative number.

like image 53
r2evans Avatar answered Sep 21 '22 23:09

r2evans