[R] Sort Problem

Liaw, Andy andy_liaw at merck.com
Thu Apr 6 14:31:55 CEST 2006


From: Sean Davis
> 
> On 4/6/06 8:04 AM, "Sumanta Basak" <sumanta24 at gmail.com> wrote:
> 
> > Hi All,
> > 
> > 
> > 
> > I have certain combinations for which I have some value, e.g.
> > 
> > 
> > 
> > 0 1         20
> > 
> > 0 2         15
> > 
> > 1 1         40
> > 
> > 1 2         52
> > 
> > 
> > 
> > Now I need to sort this list for which I'll get the combination 
> > against the lowest value. In this case, 15, and the 
> combination will 
> > be 0 2.
> 
> See ?order.  You can use the ordering that you get from 
> order() to grab the appropriate entry in your matrix/data.frame.
> 
> Sean

If Sumanta just wants the entry with the minimum, there's no need to sort
the whole thing.  which.min() should work.

Andy




More information about the R-help mailing list