tedzzx
2009-Mar-19 13:15 UTC
[R] find the index of the smallest or biggest number in a vetor or data.frame
Dear R experts, How to find out the index of minimum or maxmum number in a vetor or data.frame? For example, a n price 1 50 -2 100 0 200 -1 300 ...... I want to find out the row which the n is the smallest or largestest and extract the price. Thanks Ted -- View this message in context: http://www.nabble.com/find-the-index-of-the-smallest-or-biggest-number-in-a-vetor-or-data.frame-tp22599905p22599905.html Sent from the R help mailing list archive at Nabble.com.
Henrique Dallazuanna
2009-Mar-19 14:59 UTC
[R] find the index of the smallest or biggest number in a vetor or data.frame
Try this: # for the minimum a$price[which.min(a$n)] # for the maximum a$price[which.max(a$n)] On Thu, Mar 19, 2009 at 10:15 AM, tedzzx <zengzhenxing@gmail.com> wrote:> > Dear R experts, > > How to find out the index of minimum or maxmum number in a vetor or > data.frame? > > For example, > > a> > n price > 1 50 > -2 100 > 0 200 > -1 300 > ...... > > > I want to find out the row which the n is the smallest or largestest and > extract the price. > > > Thanks > > Ted > -- > View this message in context: > http://www.nabble.com/find-the-index-of-the-smallest-or-biggest-number-in-a-vetor-or-data.frame-tp22599905p22599905.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Tsjerk Wassenaar
2009-Mar-19 15:00 UTC
[R] find the index of the smallest or biggest number in a vetor or data.frame
?which On Thu, Mar 19, 2009 at 2:15 PM, tedzzx <zengzhenxing at gmail.com> wrote:> > Dear R experts, > > How to find out the index of minimum or maxmum number in a vetor or > data.frame? > > For example, > > a> > n ? price > 1 ? ? 50 > -2 ? ?100 > 0 ? ?200 > -1 ? 300 > ...... > > > I want to find out the row which the n is the smallest or largestest and > extract the price. > > > Thanks > > Ted > -- > View this message in context: http://www.nabble.com/find-the-index-of-the-smallest-or-biggest-number-in-a-vetor-or-data.frame-tp22599905p22599905.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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. >-- Tsjerk A. Wassenaar, Ph.D. Junior UD (post-doc) Biomolecular NMR, Bijvoet Center Utrecht University Padualaan 8 3584 CH Utrecht The Netherlands P: +31-30-2539931 F: +31-30-2537623