Extract or replace the antidiagonal of a matrix, or construct a antidiagonal matrix.
antidiag(x = as.numeric(c(1)), nrow = NULL, ncol = NULL) antidiag(x) <- value
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. |
#> [1] 0 1 0# Creating antidiagonal matrix antidiag(7, 3, 3)#> [,1] [,2] [,3] #> [1,] 0 0 7 #> [2,] 0 7 0 #> [3,] 7 0 0antidiag(1:5, 3, 3)#> [,1] [,2] [,3] #> [1,] 0 0 1 #> [2,] 0 2 0 #> [3,] 3 0 0#> [,1] [,2] [,3] #> [1,] 0 0 3 #> [2,] 0 4 0 #> [3,] 5 0 0