On Wednesday, July 15, 2009 8:28 AM, jurgen claesen wrote: > ...I'm a relative new user of R and I have a > problem with merging a collection of > matrices. All matrices in this collection > have the same dimension (532 rows and 532 > columns), but can differ in the row and > columns names. I'd like to merge these > matrices in such a way that the resulting > matrix only contains unique row- and > column-names and that in case of a match > between the row or column names the smallest > value is retained.... > As an example says more: > > A1<-matrix(c(1:9), ncol=3, byrow=TRUE) > rownames(A1)<-colnames(A1)<-c("a","b","c") > > a b c > a 1 2 3 > b 4 5 6 > c 7 8 9 > > A2<-matrix(c(7,1,3,10,2,7,3,1,8),ncol=3,byrow=TRUE) > rownames(A2)<-colnames(A2)<-c("a","y","z") > > a y z > a 7 1 3 > y 10 2 7 > z 3 1 8 > > I want something like this to be returned: > > a b c y z > a 1 2 3 1 3 > b 4 5 6 NA NA > c 7 8 9 NA NA > y 10 NA NA 5 6 > z 3 NA NA 8 9 >
Two questions (a) how do you want to decide which of the elements gets dropped out---like the value 7 in A2 [1,1] above and (b) what goes in the bottom corner of the new matrix? I would have guessed i would have seen 2 7 1 8 in the corner. Was that a typo or do you really want to overwrite the values of the submatrix that *is* in A1? david -- David ----------------------------------------------------- David Huffer, Ph.D. Senior Statistician CSOSA/Washington, DC david.huf...@csosa.gov ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.