[R] ordering problem

Moshe Olshansky m_olshansky at yahoo.com
Wed Oct 8 04:51:44 CEST 2008


Try 

AA <- apply(A,1,function(x) paste(x,collapse=""))

and work with AA.


--- On Tue, 30/9/08, Jose Luis Aznarte M. <jlaznarte at decsai.ugr.es> wrote:

> From: Jose Luis Aznarte M. <jlaznarte at decsai.ugr.es>
> Subject: [R] ordering problem
> To: r-help at stat.math.ethz.ch
> Received: Tuesday, 30 September, 2008, 8:43 PM
> Hi there!
>         I need some assistance here with vector orderings.
> I have a set 
> of q vectors of length p, grouped by rows in a matrix A,
> q·p, that I 
> need to order lexicographically 
> (http://en.wikipedia.org/wiki/Lexicographical_order).
>         I also have another matrix B, p·r, and a vector c,
> that should 
> be ordered according to the order of A. So far, I was doing
> 
>     ordering <-  apply(A, 2, order)[,1]
>     A <- A[ordering,]
>     B <- B[ordering,]
>     c <- c[ordering]
> 
>         But now I realize that this way I'm ordering by
> considering only 
> the first dimension of the vectors in A, i.e., not
> considering the case 
> where there are ties amongst this first dimension. Does
> anyone have a 
> clue about properly applying the lexicographical ordering?
> Thanks in 
> advance!
> 
>  
> --                                                      --
> Jose Luis Aznarte M.       http://decsai.ugr.es/~jlaznarte
> Department of Computer Science and Artificial Intelligence
> Universidad de Granada           Tel. +34 - 958 - 24 04 67
> GRANADA (Spain)                  Fax: +34 - 958 - 24 00 79
> 
> ______________________________________________
> 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.



More information about the R-help mailing list