Diag {lazy.mat} | R Documentation |
Diag(x) creats a diagonam matrix from its argument vector or matrix
Diag(x, drop = FALSE)
x |
Input square matrix or scalar |
drop |
= 1 to make the result a scalar when Diag(x) is 1 x 1. |
Diag(x) returns a diagonal matrix whose diagonal elements are:
1) the diagonal elements of x when x is a genuine matrix,
2) x when x is a vector, row vector, or column vector.
Can be used with a character matrix
A diagonal matrix
Diag(demomat(2,2)) Diag(1:3) Diag(matrix(1:3,1)) Diag(2) Diag(demomat(2,2,root="a")) Diag(diag(demomat(2,2,root="a"))) # from character vector Diag(paste("a",1:3,sep="")) ## Not run: # Semi Symbolic Partitioned Matrix: Super Matrix with SMdim attributes library(lazy.symbolic2) A <- demomat(c(2,3),c(2,3),root="a") Printb(A) resA <- Diag(A,A) Printb(resA) resAB <- b_diag(A,demomat(2,2,root="b"),A) Printb(resAB, sep=".") # Fully Symbolic Partitioned Matrix: No SMdim attribute but fullsymb attribute Ap <- demomat(2,2,root="A", fullsymb=1) Printb(Ap) resAp <- Diag(Ap) Printb(resAp) resABp <- b_diag(Ap,demomat(2,2,root="b"),Ap) Printb(resABp, sep=".") ## End(Not run)