[R] collapse rows in a matrix
yiping.fan@syngenta.com
yiping.fan at syngenta.com
Fri Nov 15 18:35:48 CET 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list