A <- matrix(1:4, 2, 2, dimnames=list(c("x1","x2"), c("A","B")))
B <- matrix(5:8, 2, 2, dimnames=list(c("x3","x4"), c("C","D")))
result <- array(0, dim=dim(A)+dim(B),
                dimnames=list(c(dimnames(A)[[1]], dimnames(B)[[1]]),
                              c(dimnames(A)[[2]], dimnames(B)[[2]])))
result[        1:nrow(A),         1:ncol(A)] <- A
result[nrow(A)+1:nrow(B), ncol(A)+1:ncol(B)] <- B
result

Rich

On Thu, Apr 21, 2011 at 10:03 AM, Marten Winter <marten.win...@ufz.de>wrote:

> Heja,
>
> I hope someone is still there to help me:
>
> How can I somehow merge/combine matrices to get such a result:
>
> Matrix A
>
> A B
> x1 1 0
> x2 1 1
>
> Matrix B
>
> C D
> x3 1 0
> x4 0 1
>
> Resulting Matrix?
>
>
> A B C D
> x1 1 0 0 0
> x2 1 1 0 0
> x3 0 0 1 0
> x4 0 0 0 1
>
>
> Does anyone see this probably obvious solution with R how to do this?
> Sorry if this question is silly...it's too hot here to think properly ;O)
>
> Thanks!
> cheers
> Marten
>
> --
>
> --------------------------------------------------------------------------------------------
>
> Dr. Marten Winter / Researcher
> Biozönoseforschung / Community Ecology
>
> Helmholtz-Zentrum für Umweltforschung GmbH - UFZ
> Helmholtz Centre for Environmental Research GmbH - UFZ
> Theodor-Lieser-Str. 4  / 06120 Halle (Saale) / Germany
> Telefon +49 345 558 5316 / Fax +49 345 558 5329
> marten.win...@ufz.de / www.ufz.de/index.php?en=7081
>
> Sitz der Gesellschaft: Leipzig
> Registergericht: Amtsgericht Leipzig, Handelsregister Nr. B 4703
> Vorsitzender des Aufsichtsrats: MinR Wilfried Kraus
> Wissenschaftlicher Geschäftsführer: Prof. Dr. Georg Teutsch
> Administrativer Geschäftsführer: Dr. Andreas Schmidt
>
>
> --------------------------------------------------------------------------------------------
>
> DAISIE - Delivering Alien Invasive Species Inventories for Europe
> www.europe-aliens.org
>
>
> ______________________________________________________________________________________________________________
>
> „Fakten bedeuten gar nichts! Mit Fakten kann man ja alles beweisen, was
> auch nur im Entferntesten wahr ist!“
>
> „Facts are meaningless! You could use facts to prove anything that's even
> remotely true!”
> (Homer Simpson)
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to