[R] Sorting a matrix?

Thomas Lumley tlumley at u.washington.edu
Fri Dec 7 21:18:31 CET 2001


On Fri, 7 Dec 2001, Duncan Murdoch wrote:

> I'd like to sort the rows of a matrix, sorting by the values in the
> 1st column, breaking ties by the 2nd, etc.  I don't know in advance
> how many columns there'll be.
>
> Is there a way to force the unknown number of columns of my matrix to
> be the ... arguments of order(), or is there another way to do this
> (other than a loop)?

You should be able to do this with do.call(), which takes a function name
and a list of arguments.  Something like

do.call("order",lapply(1:NCOL(m) function(i) m[,i]))

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list