Feng Qiu
2007-Jan-18 04:20 UTC
[R] how to get the index of entry with max value in an array?
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]]
Prof Brian Ripley
2007-Jan-18 04:50 UTC
[R] how to get the index of entry with max value in an array?
?which.max ?which.is.min On Wed, 17 Jan 2007, Feng Qiu 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
jim holtman
2007-Jan-18 04:51 UTC
[R] how to get the index of entry with max value in an array?
which.max> a <- sample(1:10,10) > a[1] 3 4 5 7 2 8 9 6 10 1> which.max(a)[1] 9>On 1/17/07, Feng Qiu <hellokisas@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@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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
Christos Hatzis
2007-Jan-18 04:52 UTC
[R] how to get the index of entry with max value in an array?
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.
Benilton Carvalho
2007-Jan-18 05:20 UTC
[R] how to get the index of entry with max value in an array?
which.max() b On Jan 17, 2007, at 11:20 PM, Feng Qiu 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
Feng Qiu
2007-Jan-18 05:49 UTC
[R] how to get the index of entry with max value in an array?
Thank you guys! I got it. Best, Feng ----- Original Message ----- From: "Benilton Carvalho" <bcarvalh at jhsph.edu> To: "Feng Qiu" <hellokisas at gmail.com> Cc: <r-help at stat.math.ethz.ch> Sent: Thursday, January 18, 2007 12:20 AM Subject: Re: [R] how to get the index of entry with max value in an array?> which.max() > b > > On Jan 17, 2007, at 11:20 PM, Feng Qiu 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