Does anyone know how to execute the following sort problem in R? Matrix X
has positive integer entries, and each column has been sorted in ascending
order. The problem is now to order the columns lexicographically. For
instance if the matrix X is

 

1 2 1 1 2

2 2 3 3 2

3 5 5 4 2

 

then the result should be

 

1 1 1 2 2

2 3 3 2 2

3 4 5 2 5

 

Let ONE be a vector of 1's of length ncol(X). The result in this example can
be accomplished by

 

X=X[,order(ONE,X[1,],X[,2],X[,3])]

 

but I need a method that will work regardless of k=number of rows of X. That
is, the program must be able to accept any integer-valued matrix X for which
each column is sorted, then permute columns accordingly. 

 

Thanks, JP

 

 


	[[alternative HTML version deleted]]


