Dear all, x <- matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow = T)> x[,1] [,2] [,3] [,4] [,5] [1,] 1239 10 10 10 10 [2,] 1234 10 10 10 10 [3,] 1500 11 11 11 11 [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13 I tried to sort by 1st column, but stayed the other columns as they were. I mean [,1] [,2] [,3] [,4] [,5] [2,] 1234 10 10 10 10 [1,] 1239 10 10 10 10 -------------------------------------- [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [3,] 1500 11 11 11 11 -------------------------------------- [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 -------------------------------------- [8,] 1458 13 13 13 13 any suggestions? thanks ashley -- View this message in context: http://www.nabble.com/partially-sorting--tp24710996p24710996.html Sent from the R help mailing list archive at Nabble.com.
Dear all, x <- matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow = T)> x[,1] [,2] [,3] [,4] [,5] [1,] 1239 10 10 10 10 [2,] 1234 10 10 10 10 [3,] 1500 11 11 11 11 [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13 I tried to sort by 1st column, but stayed the other columns as they were. I mean [,1] [,2] [,3] [,4] [,5] [2,] 1234 10 10 10 10 [1,] 1239 10 10 10 10 -------------------------------------- [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [3,] 1500 11 11 11 11 -------------------------------------- [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 -------------------------------------- [8,] 1458 13 13 13 13 any suggestions? thanks ashley -- View this message in context: http://www.nabble.com/partially-sorting--tp24711191p24711191.html Sent from the R help mailing list archive at Nabble.com.
Is this what you want? You may have to include other columns for other levels of uniqueness:> x[,1] [,2] [,3] [,4] [,5] [1,] 1239 10 10 10 10 [2,] 1234 10 10 10 10 [3,] 1500 11 11 11 11 [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13> x[order(x[,2], x[,1]),][,1] [,2] [,3] [,4] [,5] [1,] 1234 10 10 10 10 [2,] 1239 10 10 10 10 [3,] 1001 11 11 11 11 [4,] 1009 11 11 11 11 [5,] 1500 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13>On Tue, Jul 28, 2009 at 10:07 PM, ashley2000<ashley.askew2000 at gmail.com> wrote:> > Dear all, > > x <- > matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, > > 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow > = T) > >> x > ? ? [,1] [,2] [,3] [,4] [,5] > [1,] 1239 ? 10 ? 10 ? 10 ? 10 > [2,] 1234 ? 10 ? 10 ? 10 ? 10 > [3,] 1500 ? 11 ? 11 ? 11 ? 11 > [4,] 1001 ? 11 ? 11 ? 11 ? 11 > [5,] 1009 ? 11 ? 11 ? 11 ? 11 > [6,] 1344 ? 12 ? 12 ? 12 ? 12 > [7,] 1349 ? 12 ? 12 ? 12 ? 12 > [8,] 1458 ? 13 ? 13 ? 13 ? 13 > > I tried to sort by 1st column, but stayed the other columns as they were. I > mean > > > > ? ? [,1] [,2] [,3] [,4] [,5] > [2,] 1234 ? 10 ? 10 ? 10 ? 10 > [1,] 1239 ? 10 ? 10 ? 10 ? 10 > -------------------------------------- > [4,] 1001 ? 11 ? 11 ? 11 ? 11 > [5,] 1009 ? 11 ? 11 ? 11 ? 11 > [3,] 1500 ? 11 ? 11 ? 11 ? 11 > -------------------------------------- > [6,] 1344 ? 12 ? 12 ? 12 ? 12 > [7,] 1349 ? 12 ? 12 ? 12 ? 12 > -------------------------------------- > [8,] 1458 ? 13 ? 13 ? 13 ? 13 > > > > any suggestions? > > thanks > > ashley > -- > View this message in context: http://www.nabble.com/partially-sorting--tp24711191p24711191.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
> x <-+ matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, + + 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow + = T)> x[order(x[,1]),][,1] [,2] [,3] [,4] [,5] [1,] 1001 11 11 11 11 [2,] 1009 11 11 11 11 [3,] 1234 10 10 10 10 [4,] 1239 10 10 10 10 [5,] 1344 12 12 12 12 [6,] 1349 12 12 12 12 [7,] 1458 13 13 13 13 [8,] 1500 11 11 11 11 see ?order regards, nik ---------------------------------------------- Andreas Dominik Cullmann Forstliche Versuchs- und Forschungsanstalt Wonnhalde 4 79100 Freiburg Tel. +49 761 4018 204 Email: dominik.cullmann at forst.bwl.de <mailto:dominik.cullmann at forst.bwl.de> Homepage: www.fva-bw.de <http://www.fva-bw.de>> -----Urspr?ngliche Nachricht----- > Von: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Im Auftrag von ashley2000 > Gesendet: Mittwoch, 29. Juli 2009 03:44 > An: r-help at r-project.org > Betreff: [R] partially sorting? > > > Dear all, > > x <- > matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,10 > 01,11,11,11,11, > > 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13, > 13,13),8,5,byrow > = T) > > > x > [,1] [,2] [,3] [,4] [,5] > [1,] 1239 10 10 10 10 > [2,] 1234 10 10 10 10 > [3,] 1500 11 11 11 11 > [4,] 1001 11 11 11 11 > [5,] 1009 11 11 11 11 > [6,] 1344 12 12 12 12 > [7,] 1349 12 12 12 12 > [8,] 1458 13 13 13 13 > > I tried to sort by 1st column, but stayed the other columns > as they were. I > mean > > > > [,1] [,2] [,3] [,4] [,5] > [2,] 1234 10 10 10 10 > [1,] 1239 10 10 10 10 > -------------------------------------- > [4,] 1001 11 11 11 11 > [5,] 1009 11 11 11 11 > [3,] 1500 11 11 11 11 > -------------------------------------- > [6,] 1344 12 12 12 12 > [7,] 1349 12 12 12 12 > -------------------------------------- > [8,] 1458 13 13 13 13 > > > > any suggestions? > > thanks > > ashley > -- > View this message in context: > http://www.nabble.com/partially-sorting--tp24710996p24710996.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
> x <-+ matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, + + 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow + = T)> x[,1] [,2] [,3] [,4] [,5] [1,] 1239 10 10 10 10 [2,] 1234 10 10 10 10 [3,] 1500 11 11 11 11 [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13> ind <- do.call(order, data.frame(x[,c(2:5,1)])) > xs <- x[ind, ] > xs[,1] [,2] [,3] [,4] [,5] [1,] 1234 10 10 10 10 [2,] 1239 10 10 10 10 [3,] 1001 11 11 11 11 [4,] 1009 11 11 11 11 [5,] 1500 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13>Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of ashley2000 Sent: Wednesday, 29 July 2009 12:07 PM To: r-help at r-project.org Subject: [R] partially sorting? Dear all, x <- matrix(c(1239,10,10,10,10,1234,10,10,10,10,1500,11,11,11,11,1001,11,11,11,11, 1009,11,11,11,11,1344,12,12,12,12,1349,12,12,12,12,1458,13,13,13,13),8,5,byrow = T)> x[,1] [,2] [,3] [,4] [,5] [1,] 1239 10 10 10 10 [2,] 1234 10 10 10 10 [3,] 1500 11 11 11 11 [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 [8,] 1458 13 13 13 13 I tried to sort by 1st column, but stayed the other columns as they were. I mean [,1] [,2] [,3] [,4] [,5] [2,] 1234 10 10 10 10 [1,] 1239 10 10 10 10 -------------------------------------- [4,] 1001 11 11 11 11 [5,] 1009 11 11 11 11 [3,] 1500 11 11 11 11 -------------------------------------- [6,] 1344 12 12 12 12 [7,] 1349 12 12 12 12 -------------------------------------- [8,] 1458 13 13 13 13 any suggestions? thanks ashley -- View this message in context: http://www.nabble.com/partially-sorting--tp24711191p24711191.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.