[R] Sort a data frame with respect to more than one variable

Romain Francois francoisromain at free.fr
Wed Sep 21 11:06:49 CEST 2005


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    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~




More information about the R-help mailing list