[R] order a matrix

Christian Hennig chrish at stats.ucl.ac.uk
Mon Nov 5 19:05:17 CET 2007


That solved it!

Thank you very much!

On Mon, 5 Nov 2007, Prof Brian Ripley wrote:

> On Mon, 5 Nov 2007, Christian Hennig wrote:
>
>> Dear list,
>> 
>> order(x,y,z) returns a permutation to order x, ties broken by y, remaining
>> ties broken by z. (And so on.)
>> 
>> What I'd like to do is
>> order(X), where X is a matrix (or a list or data frame if necessary) of
>> unspecified size, which orders X[,1], ties broken by X[,2], remaining ties
>> broken by X[,3] and so on - without having to know and to write down how
>> many columns  X has.
>> 
>> Any ideas how to achieve that?
>
> For a list or data frame, do.call("order", X).
> For a matrix, do.call("order", split(A, col(A))).
>
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>

*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chrish at stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche



More information about the R-help mailing list