Description Usage Arguments Details Value Note See Also Examples

Generate diagonal matrices or return diagonal of a matrix

1 | ```
Diag(x, k = 0)
``` |

`x` |
vector or matrix |

`k` |
integer indicating a secondary diagonal |

If `x`

is a vector, `Diag(x, k)`

generates a matrix with `x`

as the (k-th secondary) diagonal.

If `x`

is a matrix, `Diag(x, k)`

returns the (`k`

-th secondary) diagonal of `x`

.

The `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 |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.