Skip to content
Back to formatted view

Raw Message

Message-ID: <433122A9.2030707@free.fr>
Date: 2005-09-21T09:06:49Z
From: Romain Francois
Subject: Sort a data frame with respect to more than one variable
In-Reply-To: <20050921085431.75995.qmail@web25807.mail.ukl.yahoo.com>

Le 21.09.2005 10:54, Marc Bernard a ??crit :

>Dear All,
> 
>How can I sort a data frame with respect to more than one  variable?
> 
>I know that for one variable X  one may use:   df[order(df$X), ] where df is  the data frame containing X.
> 
>Many thanks,
> 
>Bernard
>  
>
You already know the answer of that question. order() accepts more than 
one variable.

x <- rep(rbinom(5,size=4,prob=.5), 6)
y <- rnorm(30)
cbind(x,y)[ order(x,y) , ]

Romain

-- 
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
~~~~~~      Romain FRANCOIS - http://addictedtor.free.fr         ~~~~~~
~~~~        Etudiant  ISUP - CS3 - Industrie et Services           ~~~~
~~                http://www.isup.cicrp.jussieu.fr/                  ~~
~~~~           Stagiaire INRIA Futurs - Equipe SELECT              ~~~~
~~~~~~   http://www.inria.fr/recherche/equipes/select.fr.html    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~