Hi Thomas.
For just two matrices (say, A & B), this is easy:
aa<-sort(unique(c(rownames(A),rownames(B))))
bb<-sort(unique(c(colnames(A),colnames(B))))
XX<-matrix(NA,length(aa),length(bb),dimnames=list(aa,bb))
XX[rownames(A),colnames(B)]<-A
XX[rownames(B),colnames(B)]<-B
There may be some easier way to do this; and if your matrices were put
in a list (say, when they were read into memory) we could easily apply
even the method above automatically across the list automatically with
no difficulty.
Say, for list of matrices YY:
aa<-sort(unique(sapply(YY,rownames)))
bb<-sort(unique(sapply(YY,colnames)))
XX<-matrix(NA,length(aa),length(bb),dimnames=list(aa,bb))
for(i in 1:length(YY)) XX[rownames(YY[[i]]),colnames(YY[[i]])]<-YY[[i]]
at least.
Hope this is helpful. Liam
Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org
On 3/20/2013 3:07 PM, thom.g wrote:
Hi,
I have a certain number of character matrices that I want to merge together but
unfortunately all the matrices don't have the same number of taxa and
characters. However there is always more than one character/taxa in common
between each matrix.
I have something like that:
Taxa Character1 Character2 Character4
Taxon1 0 0 0
Taxon2 0 0 1
Taxon5 0 1 1
Taxa Character2 Character3 Character5
Taxon3 0 1 1
Taxon4 1 0 1
Taxon5 1 1 1
And I'd like something like that:
Taxa Character1 Character2 Character3 Character4 Character5
Taxon1 0 0 ? 0 ?
Taxon2 0 0 ? 1 ?
Taxon3 ? 0 1 ? 1
Taxon4 ? 1 0 ? 1
Taxon5 0 1 1 1 1
Does someone already worked on this problem on R? The difference R base
functions like merge() or aggregate() don't do the job unfortunately.
Thanks,
Thomas.
================
Thomas Guillerme
Trinity Postgraduate Research Studentship
Macroecology and Macroevolution Research Group
Zoology Department
School of Natural Sciences
Trinity College Dublin
2 College Green, Dublin 2
guill...@tcd.ie
@TGuillerme
+353877021326
http://www.tcd.ie/Zoology/research/ncooper/people.php
[[alternative HTML version deleted]]
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/