Dear All, Let ab is the combination of matrices a and b. a <- matrix(c(1,2,3,4), nrow = 2, ncol = 2) b <- matrix(c(4,3,1,2), nrow = 2, ncol = 2) ab <- rbind(a, b) ? From matrix ab, could someone give some advice on the way to sort?all?elements in column 2, by?the sequence of the elements in?column 1 in ascending order? ? Thank you. Fir
Hi, On Sep 22, 2009, at 1:20 PM, FMH wrote:> Dear All, > > Let ab is the combination of matrices a and b. > > > a <- matrix(c(1,2,3,4), nrow = 2, ncol = 2) > b <- matrix(c(4,3,1,2), nrow = 2, ncol = 2) > ab <- rbind(a, b) > >> From matrix ab, could someone give some advice on the way to sort >> all elements in column 2, by the sequence of the elements in column >> 1 in ascending order?R> ab[order(ab[,1]),2] [1] 3 4 2 1 -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
ab[order(ab[,1]),] ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von FMH Gesendet: Tuesday, September 22, 2009 1:20 PM An: r-help at r-project.org Betreff: [R] How to sort the elements in a matrix? Dear All, Let ab is the combination of matrices a and b. a <- matrix(c(1,2,3,4), nrow = 2, ncol = 2) b <- matrix(c(4,3,1,2), nrow 2, ncol = 2) ab <- rbind(a, b) ?>From matrix ab, could someone give some advice on the way tosort?all?elements in column 2, by?the sequence of the elements in?column 1 in ascending order? ? Thank you. Fir ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On Sep 22, 2009, at 1:20 PM, FMH wrote:> Dear All, > > Let ab is the combination of matrices a and b. > > > a <- matrix(c(1,2,3,4), nrow = 2, ncol = 2) > b <- matrix(c(4,3,1,2), nrow = 2, ncol = 2) > ab <- rbind(a, b) > >> From matrix ab, could someone give some advice on the way to sort >> all elements in column 2, by the sequence of the elements in column >> 1 in ascending order?ab[ ,2][ order(ab[,1]) ] #[1] 3 4 2 1> > Thank you. > Fir > > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD Heritage Laboratories West Hartford, CT