[R] argmax

Doran, Harold HDoran at air.org
Wed Apr 4 17:22:26 CEST 2007


x <- c(1,4,15,6,7)
which(x==max(x)) 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> croero at hotmail.com
> Sent: Wednesday, April 04, 2007 11:14 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] argmax
> 
> Hello,
>  
> Is there any function that returns the argmax of a vector ?
>  
> For example I have the vector x=(1,4,15,6,7)
>  
> max(x)=15
>  
> I want a function f such that f(x)=3 because this is where max(x) is.
>  
> Thank your very much.
>  
> P.S. : I know it is a basic question but I have not figured 
> it out by myself.
> _________________________________________________________________
> 
> ues clics pour retrouver tout ce qui vous intéresse au même endroit.
> 
> 	[[alternative HTML version deleted]]
> 
>



More information about the R-help mailing list