Skip to content
Prev 169577 / 398506 Next

How to sort a matrix or dataframe by two columns?

Yes, you can:

m <- matrix( sample(1:5, 20, rep=TRUE), nc=2)
m[ order(m[,1],m[,2]), ]

Gabor
On Fri, Feb 6, 2009 at 11:29 PM, Bill Hyman <billhyman1 at yahoo.com> wrote: