[6391] in s-news-athena
Re: sorting a matrix
daemon@ATHENA.MIT.EDU (John Wallace)
Fri Feb 3 19:33:20 1995
Date: Fri, 3 Feb 1995 16:20:24 -0800 (PST)
From: John Wallace <jrw@fish.washington.edu>
To: "Franz J. Mueter" <mueter@sterling.ims.alaska.edu>
Cc: S-news@utstat.toronto.edu
In-Reply-To: <9502031951.AA18104@sterling.ims.alaska.edu>
Use,
x[order(x[, col]), ]
Here is a small function with column and reverse:
sortmat <- function(x, col = 1, reverse = F)
{
if(reverse)
x[rev(order(x[, col])), ]
else x[order(x[, col]), ]
}
-jrw
On Fri, 3 Feb 1995, Franz J. Mueter wrote:
> This seems like a trivial task, but I could not
> find an easy way to sort a matrix by one column;
> i.e such that the order of all rows in the matrix
> is determined by the values in one of the columns.
>
> Any suggestions would be greatly appreciated!
>
> Franz Mueter ph: (907)474-7839
> Inst. of Marine Sciences email: mueter@ims.alaska.edu
> University of Alaska Fairbankis
>
>
>