[R] how to get the index of entry with max value in an array?

Christos Hatzis christos at nuverabio.com
Thu Jan 18 05:52:01 CET 2007


Or
which.max(a)

-Christos 

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of talepanda
Sent: Wednesday, January 17, 2007 11:45 PM
To: Feng Qiu
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] how to get the index of entry with max value in an array?

In R language, one solution is:

a<-c(3,4,6,2,3)
which(a==max(a))


On 1/18/07, Feng Qiu <hellokisas at gmail.com> wrote:
> Hi all:
>          A short question:
>          For example,  a=[3,4,6,2,3], obviously the 3rd entry of the 
> array has the maxium value, what I want is index of the maxium value: 
> 3. is there a neat expression to get this index?
>
> Thank you!
>
> Best,
>
> Feng
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list