Package 'diagonals'

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

Help Index


diagonals

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.

Author(s)

Bastiaan Quast [email protected]

See Also

https://qua.st/diagonals


Fat Matrix Diagonals

Description

Fat Matrix Diagonals

fatdiag set

Usage

fatdiag(x = 1, steps = NULL, size = NULL, nrow = NULL, ncol = NULL)

fatdiag(x, steps = NULL, size = NULL, on_diagonal = TRUE) <- value

Arguments

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

Details

Either steps or size is expected to be provided.

Functions

  • fatdiag<-: the set version of fatdiag

Examples

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

Description

Split Vector

Usage

split_vector(x, steps = NULL, size = NULL, replacement = 0)

Arguments

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).

Details

Either steps or size is expected to be provided.