Skip to content

How to sort a dataframe?

2 messages · Ravi Varadhan, Spencer Graves

#
How does one sort a dataframe on multiple columns, say you first sort 
on variable 1 and then on variable 2, etc.? Is there a simple, one-
liner to do this?

thanks,
Ravi.

----- Original Message -----
From: Spencer Graves <spencer.graves at pdf.com>
Date: Monday, April 7, 2003 2:07 pm
Subject: Re: [R] How to sort a dataframe?
#
> df1[order(df1$b, df1$a),]
   a b c
4 1 1 4
3 2 1 3
2 1 2 2
1 2 2 1

Spencer Graves
Ravi Varadhan wrote: