Re: [R] How to sort a matrix or dataframe by two columns?

2009-02-06 Thread Bill Hyman
Gabor,

Thank you very much!

Bill



- Original Message 
From: Gábor Csárdi 
To: Bill Hyman 
Cc: r-help@r-project.org
Sent: Friday, February 6, 2009 2:37:30 PM
Subject: Re: [R] 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  wrote:
> Dear all,
>
> I have a matrix data and would like to sort it by col 1 first and then sort 
> it by col 2. Can I do it in R? Thanks a lot!
>
> Bill
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to sort a matrix or dataframe by two columns?

2009-02-06 Thread Gábor Csárdi
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  wrote:
> Dear all,
>
> I have a matrix data and would like to sort it by col 1 first and then sort 
> it by col 2. Can I do it in R? Thanks a lot!
>
> Bill
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi  UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to sort a matrix or dataframe by two columns?

2009-02-06 Thread Bill Hyman
Dear all,

I have a matrix data and would like to sort it by col 1 first and then sort it 
by col 2. Can I do it in R? Thanks a lot!

Bill

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.