[R] inverse lexicographical ordering

Daniel Malter daniel at umd.edu
Fri Feb 19 18:42:50 CET 2010

```Hi, see the code below. Next time, please provide self-contained code to
generate the matrix (read the posting guide) so that we can just copy-paste
it into R to get the matrix.

x=rep(c(0,1),4)
y=rep(c(0,0,1,1),2)
z=rep(c(0,1),each=4)

m=cbind(z,y,x)

w=rowSums(m)

m=cbind(m,w)
m

m[order(w,x,y,z),]

HTH,
Daniel

-------------------------
cuncta stricte discussurus
-------------------------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Evgenia
Sent: Friday, February 19, 2010 12:10 PM
To: r-help at r-project.org
Subject: [R] inverse lexicographical ordering

Dear users,

I have a matrix b as

[,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    1    1
[3,]    0    1    0    1
[4,]    0    1    1    2
[5,]    1    0    0    1
[6,]    1    0    1    2
[7,]    1    1    0    2
[8,]    1    1    1    3

with last column the rowSums(b)
I want for each value of last column of b separately (b:0,1,2,3,  to sort
the above table  by reverse lexicographical order.
For the above table the result should be

1  0  0  0
2  1  0  0
3  0  1  0
4  0  0  1
5  1  1  0
6  1  0  1
7  0  1  1
8  1  1  1

Could anyone help me with this?
Thanks alot

Evgenia

--
View this message in context:
http://n4.nabble.com/inverse-lexicographical-ordering-tp1561930p1561930.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