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.tot
ID 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.merged
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 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]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to