Re: [R] Block-diagonal matrix

From: Robin Hankin <r.hankin_at_noc.soton.ac.uk>
Date: Thu 01 Sep 2005 - 16:57:32 EST

Hi

adiag() from the magic package does what you want:

 > library(magic)
Loading required package: abind

 > a <- matrix(1,2,2)
 > b <- matrix(6,2,3)
 > adiag(a,b)
      [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    0    0    0
[2,]    1    1    0    0    0

[3,] 0 0 6 6 6
[4,] 0 0 6 6 6
 >

HTH rksh

On 1 Sep 2005, at 00:25, Caio Lucidius Naberezny Azevedo wrote:

> Dear R-users,
>
> Does anybody know how to construct a block-diagonal matrix (with
> the blocks being different matrixs, concerning the dimension and
> the values), without use loops ?
>
>
> Thanks all,
>
> Caio
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

______________________________________________
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
Received on Thu Sep 01 17:06:41 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 16:10:09 EST