[R] how to order a dataframe ?

Duncan Murdoch murdoch at stats.uwo.ca
Wed May 7 18:56:41 CEST 2003


On Wed, 07 May 2003 18:20:43 +0200, you wrote in message
<3EB9325B.4010906 at ariase.com>:

>Hi,
>I've got a problem which seemed simple to me at first view, but which I 
>haven't managed to solve yet. I have a dataframe, or a matrix, and I 
>would like to order it along with one of the variables/columns. I tried 
>to use order() but it remained quite unclear to me. How should I proceed ?
>Thanks in advance (I guess that's not very difficult a question for most 
>of you)

Try something like this:

x <- matrix(rnorm(100),10,10)
s <- x[order(x[,1]),]

Now s is a copy of x sorted on the first column.

Duncan Murdoch




More information about the R-help mailing list