Generate diagonal matrices or return diagonal of a matrix
Diag(x, k = 0)
vector or matrix
integer indicating a secondary diagonal
x is a vector,
Diag(x, k) generates a matrix with
as the (k-th secondary) diagonal.
x is a matrix,
Diag(x, k) returns the (
k-th secondary) diagonal of
k-th secondary diagonal is above the main diagonal for
k > 0
and below the main diagonal for
k < 0.
matrix or vector
In Matlab/Octave this function is called
diag() and has a different
signature than the corresponding function in R.
1 2 3 4 5