Learn R Programming

CGE (version 0.3.3)

dg: A Modified diag Function

Description

This function works in the way analogous to the diag function of Matlab.

Usage

dg(x)

Arguments

x

a number, vector or square matrix.

Value

If x is a number, dg returns itself. If x is a vector, a one-row matrix or a one-column matrix, dg returns a matrix with x as the main diagnol. Otherwise dg returns diag(x).

Examples

Run this code
# NOT RUN {
diag(matrix(2, 3))
dg(matrix(2, 3))
# }

Run the code above in your browser using DataLab