Skip to content
Back to formatted view

Raw Message

Message-ID: <AF84AD19B4A8D411B18500508BAF0E0E018B56F2@se-excur01-uslj.nadi.uslj>
Date: 2002-11-15T17:35:48Z
From: yiping.fan@syngenta.com
Subject: collapse rows in a matrix

Hi, all,
  I have a little problem to solve. I'd like to collapse rows which are next
to each other but have
 same value to one row. The following is an example.

say x is a data frame like:
   X1 X2 X3 X4 X5
a  1  0  0  0  1
b  1  0  1  0  1
c  1  0  0  0  1
d  1  0  0  0  1
e  1  0  0  0  1
f  1  1  0  0  1
g  1  1  0  0  1

notice that  a, c,d,e are the same. since c,d,e are next to each other, I
will only use the middle
one,i.e d.   I will also  keep a although it is the same as d.

f,g , I will keep f or g.

so the ideal output is: 
a  1  0  0  0  1
b  1  0  1  0  1
d  1  0  0  0  1
f  1  1  0  0  1

Any idea how to do it?  Thanks!!

Y. Fan
by the way,
unique(x) does not give me the desired output:  it remove c,d,e
  X1 X2 X3 X4 X5
a  1  0  0  0  1
b  1  0  1  0  1
f  1  1  0  0  1



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._