[R] Q: sort a matrix by picking up columns?
Yuyun Jessie Yang
yuyun at stat.wisc.edu
Wed Oct 13 19:11:12 CEST 1999
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list