[R] Block-diagonal matrix

Robin Hankin r.hankin at noc.soton.ac.uk
Thu Sep 1 08:57:32 CEST 2005


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 at 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




More information about the R-help mailing list