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

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Wed 21 Sep 2005 - 19:06:51 EST

if you need nested sorting then you can still use order(), e.g., in a longitudinal setting you may want to sort your data.frame with respect to subject's id and time within subject then use,

df[order(df$id, df$time), ]

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


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

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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 Received on Wed Sep 21 19:18:39 2005