[R] sort columns

Ista Zahn istazahn at gmail.com
Fri Feb 26 19:54:33 CET 2010


Hi Frederik,
Not exactly clear how you want them sorted, but one of these two is
probably what you want:

mat <- matrix(100:1, ncol=10)
mat.1 <- apply(mat, 2, sort)
mat.2 <- mat[order(10:1),]

Best,
Ista


On Fri, Feb 26, 2010 at 12:41 PM, frederik vanhaelst
<frederik.vanhaelst at gmail.com> wrote:
> Hello,
>
> i have a 50*100 matrix, with real numbers. How do i sort each column?
> Now i sort it with a for-loop but this take a lot of time...
>
> Thank you,
>
> Frederik
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list