% Generated by roxygen2: do not edit by hand
\name{diag}
\alias{diag}
\title{Diagonal Matrices and Diagonal of a Matrix}
\arguments{
  \item{x}{a vector (to create a diagonal matrix) or a matrix (to extract its diagonal)}
  \item{n}{the desired number of rows/columns for the diagonal matrix
}
}

\details{
Create a diagonal matrix from a vector
\code{
x <- 1:3
diag(x)  # diagonal matrix
}

Extract the diagonal from a matrix
\code{
A <- matrix(1:9, nrow = 3)
diag(A)  # diagonal of the matrix
}

Create an identity matrix
\code{
diag(5)  # 5x5 identity matrix
}}

