The which function may do what you want:
which(v1==max(v1))

> v1<-round(10*rnorm(8))
> v1
[1]   7  17   0 -11   1   6 -10   0
> which(v1==max(v1))
[1] 2
> max(v1)
[1] 17
> v2<-c(v1,max(v1))
> which(v2==max(v2))
[1] 2 9

You can always create logicals but what do you want returned if the max
happens more than once?

bob


-----Original Message-----
From: ryszard.czerminski@pharma.novartis.com
[mailto:ryszard.czerminski@pharma.novartis.com] 
Sent: Friday, November 14, 2003 2:06 PM
To: R-help@stat.math.ethz.ch
Subject: [R] index of max value ?

Is there a function in R, which would return index of maximum value
in a vector ?

e.g.

> v <- round(10*rnorm(8))
> v
[1]   6  -3  -6  15   7   9   0 -19
> max(v)
[1] 15

??? index.max(v)
??? 4

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

	[[alternative HTML version deleted]]


