Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sdiag

Extract or modify diagonals of a matrix


Description

Extracts or modifies sub- or super- diagonals of a matrix.

Usage

sdiag(A,k=0)
sdiag(A,k=0) <- value

Arguments

A

a matrix

k

sub- (negative) or super- (positive) diagonal of a matrix. 0 is the leading diagonal.

value

single value, or vector of the same length as the diagonal.

Value

A vector containing the requested diagonal, or a matrix with the requested diagonal replaced by value.

Author(s)

Examples

require(mgcv)
A <- matrix(1:35,7,5)
A
sdiag(A,1) ## first super diagonal
sdiag(A,-1) ## first sub diagonal

sdiag(A) <- 1 ## leading diagonal set to 1
sdiag(A,3) <- c(-1,-2) ## set 3rd super diagonal

mgcv

Mixed GAM Computation Vehicle with Automatic Smoothness Estimation

v1.8-35
GPL (>= 2)
Authors
Simon Wood <simon.wood@r-project.org>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.