antidiag: Matrix antidiagonals

Description Usage Arguments Examples

View source: R/RcppExports.R

Description

Extract or replace the antidiagonal of a matrix, or construct a antidiagonal matrix.

Usage

1
2
3
antidiag(x = as.numeric(c(1)), nrow = NULL, ncol = NULL)

antidiag(x) <- value

Arguments

x

matrix, vector or 1D array, or missing.

nrow

number of rows (optional; when x is not a matrix)

ncol

number of columns (optional; when x is not a matrix)

value

either a single value or a vector of length equal to that of the current antidiagonal. Should be of a mode which can be coerced to that of x.

Examples

1
2
3
4
5
6
7
8
9
# Extracting antidiag
antidiag(diag(3))
# Creating antidiagonal matrix
antidiag(7, 3, 3)
antidiag(1:5, 3, 3)
# Assigning antidiagonal
mat <- matrix(0, 3, 3)
antidiag(mat) <- c(3, 4, 5)
mat

matricks documentation built on March 26, 2020, 6:22 p.m.