Florence Combes
2005-Sep-16 13:55 UTC
[R] fusion of rows (as in merge()) but from only 1 matrix
Dear all, Once again I need your help ; I fond a way to do what I want but I am sure there is a better way.. maybe you can help me. I have a matrix, for example mat.tot :> mat.totID Desc M1 M2 1 1 gene1 0.5 0.2 2 2 gene2 -0.4 -0.1 3 3 gene3 1.0 1.2 4 4 gene1 0.6 0.3 5 5 gene2 -0.3 0.0 and I want to merge line 1 with line 4, and line 2 with line 5 because this is the same gene. I can do that with the "merge" function but I need to make 2 "virtual" matrices, like this :> ind<-duplicated(mat.tot$Desc) > ind[1] FALSE FALSE FALSE TRUE TRUE> mat.merged<-merge(mat.tot[ind==FALSE,],mat.tot[ind==TRUE,], by="Desc",all=TRUE)> mat.mergedDesc ID.x M1.x M2.x ID.y M1.y M2.y 1 gene1 1 0.5 0.2 4 0.6 0.3 2 gene2 2 -0.4 -0.1 5 -0.3 0.0 3 gene3 3 1.0 1.2 NA NA NA this is quite ok, but I would like to obtain something like this : Desc ID.x M1.x M2.x ID.y M1.y M2.y 1 gene1 1 0.5 0.2 4 0.6 0.3 2 gene2 2 -0.4 -0.1 5 -0.3 0.0 3 gene3 3 1.0 1.2 Is there a way to do something like "merge" but with only one matrix ? I read on identical(), reshape(), all.equal() etc but I didn't find a way. Thanks a lot, Florence. [[alternative HTML version deleted]]
vincent@7d4.com
2005-Sep-16 14:31 UTC
[R] fusion of rows (as in merge()) but from only 1 matrix
may union(x, y) intersect(x, y) setdiff(x, y) setequal(x, y) be of help ?
Florence Combes
2005-Sep-16 14:35 UTC
[R] fusion of rows (as in merge()) but from only 1 matrix
well, not because all these functions are described to be for vectors.... thanks Florence. On 9/16/05, vincent@7d4.com <vincent@7d4.com> wrote:> > may > union(x, y) > intersect(x, y) > setdiff(x, y) > setequal(x, y) > be of help ? > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >[[alternative HTML version deleted]]