[R] Order by the columns

jim holtman jholtman at gmail.com
Tue Jul 31 00:25:20 CEST 2007


?order

You could do something like:

mat[order(mat[,1], mat[,2], mat[,3]),]

On 7/29/07, Am Stat <amstat2006 at gmail.com> wrote:
> Dear useR,
>
> I have a data matrix, it has n columns, each column is a two-level variable
> with entires -1 and +1. They are randomly generated, now I want to order
> them like (for example, 5 columns case)
> -    -    -   -   -
> -    -   -   -    -
> .................
> (first several rows are the samples with all variables in low level)
>
> +   -   -    -   -
> +   -   -    -    -
> .............................
>
>
> -   +   -    -   -
>
>
> +  +   -    -   -
>
>
>
> + + + + +
>
> Is there any function in R that could let me do this order by Var1 then
> order by Var2 then...order by Var n
>
>
> Thanks very much in advance!
>
>
> Best,
>
> Leon
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list