[R] Q: sort a matrix by picking up columns?
Jan.Schelling@hydro.com
Jan.Schelling at hydro.com
Thu Oct 14 09:04:57 CEST 1999
you could use:
do.call("order", data.frame(Mat[,c(1,3,6,8,10,13)]))
NB do.call expects the name of the function to be called as the first argument
and the arguments to that function in terms of a list. This list can (I think
most easily) be obtained by using data.frame().
Regards
Jan
--------
Jan Schelling
Norsk Hydro
Research Centre
N - 3907 Porsgrunn
jan.schelling at hydro.com
From: yuyun at stat.wisc.edu on 99-10-13 05:11 PM GMT
To: r-help at stat.math.ethz.ch
cc: (bcc: Jan Schelling/HRE/Hydro)
Subject: [R] Q: sort a matrix by picking up columns?
Hi,
I am wondering how to write a function which sorts a matrix by giving a
vector of column numbers.
Suppose we have a matrix (or data frame) "Mat" and I want to obtain
order(Mat[,1], Mat[,3], Mat[,6,], Mat[,8], Mat[,10], Mat[,13])
in order to sort the matrix by those columns. Is there a way to write a
function so that I can give a vector of the column numbers
c(1,3,6,8,10,13) and do the sorting? Here we know that we cannot just
write order(Mat[,c(1,3,6,8,10,13)]), which would give a wrong answer.
Thanks for any input.
Jessie
Yuyun Jessie Yang
Dissertator, Department of Statistics
University of Wisconsin-Madison
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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