« Return to Thread: which.max2()

which.max2()

by Esmail Bonakdarian-4 :: Rate this Message:

Reply to Author | View in Thread

Hello,

which.max() only returns one index value, the one for the
maximum value. If I want the two index values for the two
largest values, is this a decent solution, or is there a
nicer/better R'ish way?

max2 <-function(v)
{
     m=which.max(v)
     v[m] = -v[m]
     m2=which.max(v)
     result=c(m, m2)
     result
}

Seems to work ok.

Thanks,
Esmail

______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

 « Return to Thread: which.max2()