Re: [R] Programming puzzle...

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [R] Programming puzzle...
From: Rashid Nassar (rnassar@duke.edu)
Date: Fri 14 Jul 2000 - 00:57:50 EST


Message-ID: <Pine.SOL.3.91.1000713105501.24274A-100000@bio3.acpub.duke.edu>

Here is a small function that was posted here some time ago by Renaud
Lancelot in response to a similar question and which I find very handy:

Sortmat.R <-
function (Mat, Sort)
# by Renaud Lancelot <lancelot@telecomplus.sn>
# Sort matrix or dataframe 'Mat', by column(s) 'Sort'.
# e.g. sortmat.R(datafr, c(2,4,1))
{
    m <- do.call("order", as.data.frame(Mat[, Sort]))
    Mat[m, ]
}

On Thu, 13 Jul 2000, Ron Wehrens wrote:

> Date: Thu, 13 Jul 2000 15:37:24 +0200 (MET DST)
> From: Ron Wehrens <rwehrens@sci.kun.nl>
> To: Rhelp <r-help@hypatia.math.ethz.ch>
> Subject: [R] Programming puzzle...
>
> Dear R guru's,
>
> 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...
>
>
> Ron
>
> -----------------------+--------------------------------------------------
> Ron Wehrens | " In a purely metaphorical sense, I am a turnip "
> Dept. of Chemometrics | (W.A. Quayle)
> University of Nijmegen | Email: rwehrens@sci.kun.nl
> Toernooiveld 1 | http://www-cac.sci.kun.nl/cac/rwehrens
> 6525 ED Nijmegen | Tel: +31 24 365 2053
> The Netherlands | Fax: +31 24 365 2653
> -----------------------+------------------------------------------------
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Thu 18 Jan 2001 - 20:01:07 EST