Title: | Block Diagonal Extraction or Replacement |
---|---|
Description: | Several tools for handling block-matrix diagonals and similar constructs are implemented. Block-diagonal matrices can be extracted or removed using two small functions implemented here. In addition, non-square matrices are supported. Block diagonal matrices occur when two dimensions of a data set are combined along one edge of a matrix. For example, trade-flow data in the 'decompr' and 'gvc' packages have each country-industry combination occur along both edges of the matrix. |
Authors: | Bastiaan Quast [aut, cre] |
Maintainer: | Bastiaan Quast <[email protected]> |
License: | GPL-3 |
Version: | 6.4.0 |
Built: | 2024-10-31 20:34:41 UTC |
Source: | https://github.com/bquast/diagonals |
Several tools for handling block-matrix diagonals and similar constructs are implemented. Block-diagonal matrices can be extracted or removed using two small functions implemented here. In addition, non-square matrices are supported. Block diagonal matrices occur when two dimensions of a data set are combined along one edge of a matrix. For example, trade-flow data in the decompr' and 'gvc' packages have each country-industry combination occur along both edges of the matrix.
Bastiaan Quast [email protected]
https://qua.st/diagonals
Fat Matrix Diagonals
fatdiag set
fatdiag(x = 1, steps = NULL, size = NULL, nrow = NULL, ncol = NULL) fatdiag(x, steps = NULL, size = NULL, on_diagonal = TRUE) <- value
fatdiag(x = 1, steps = NULL, size = NULL, nrow = NULL, ncol = NULL) fatdiag(x, steps = NULL, size = NULL, on_diagonal = TRUE) <- value
x |
a matrix where the dimensions are integer multiples of size or integer dividors of steps |
steps |
the required number of steps (block matrices) across the diagonal |
size |
the width or height of the matrix being dropped over the diagonal of matrix x |
nrow |
the number of rows |
ncol |
the number of columns |
on_diagonal |
should the operation be applied to the elements on the fat diagonal. |
value |
replacement value |
Either steps or size is expected to be provided.
fatdiag<-
: the set version of fatdiag
fatdiag(12, steps=3) ( m <- matrix(111, nrow=6, ncol=9) ) fatdiag(m, steps=3) <- 5 fatdiag(m, steps=3) fatdiag(12, size=4) fatdiag(12, size=c(3,4) )
fatdiag(12, steps=3) ( m <- matrix(111, nrow=6, ncol=9) ) fatdiag(m, steps=3) <- 5 fatdiag(m, steps=3) fatdiag(12, size=4) fatdiag(12, size=c(3,4) )
Split Vector
split_vector(x, steps = NULL, size = NULL, replacement = 0)
split_vector(x, steps = NULL, size = NULL, replacement = 0)
x |
a numeric or character vector |
steps |
the number of steps |
size |
the size of the step |
replacement |
value to be inserted on the diagonal, by default this is zero (0). |
Either steps or size is expected to be provided.