[R] Programming puzzle...
Jonathan Rougier
J.C.Rougier at durham.ac.uk
Thu Jul 13 16:12:21 CEST 2000
Hi Ron -- Too tempting! I would try something like
woppa <- matrix(1:120, 30, 4)
colorder <- do.call("order", split(woppa, row(woppa)))
Cheers, Jonathan.
On Thu, 13 Jul 2000, Ron Wehrens wrote:
> I'd like to sort the columns of a matrix according to the elements in the
> first row, and in case of a tie according to the second row, etc.
> In case of a 3xn matrix woppa, something like
>
> colorder _ order(woppa[1,], woppa[2,], woppa[3,])
>
> I just cannot seem to find a way to do this for a variable number of rows,
> e.g. if woppa has 10 or 15 rows I now manually cut and paste to have 10 - 15
> arguments in the order function. There has to be a clever way to do this...
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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