Skip to content
Prev 77576 / 398502 Next

Sort a data frame with respect to more than one variable

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


----- Original Message ----- 
From: "Marc Bernard" <bernarduse1 at yahoo.fr>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, September 21, 2005 10:54 AM
Subject: [R] Sort a data frame with respect to more than one variable
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm