switch-notation: Change specification notation

switch-notationR Documentation

Change specification notation

Description

IEA data can be "specified" by adding additional information. Three notations are useful: arrow, bracket, and from. Arrow notation is from -> to, and bracket notation is destination [source]. These functions change matrix row/column names among the notations.

  • arrow_to_from_byname() switches from arrow notation to from notation.

  • from_to_arrow_byname() switches from from notation to arrow notation.

  • arrow_to_bracket_byname() switches from arrow notation to bracket notation.

  • bracket_to_arrow_byname() switches from bracket notation to arrow notation.

Functions with the ⁠_byname⁠ suffix behave like functions in the matsbyname package. Specifically, they can work with a single matrix or a list of matrices supplied to the m argument.

Usage

arrow_to_from_byname(m, margin = c(1, 2))

from_to_arrow_byname(m, margin = c(1, 2))

arrow_to_bracket_byname(m, margin = c(1, 2))

bracket_to_arrow_byname(m, margin = c(1, 2))

Arguments

m

a single matrix or a list of matrices.

margin

the margin over which the notation switch should be made: 1 for rows, 2 for columns, or c(1, 2) (the default) for both rows and columns

Value

An object of same length as m with switched notation.

Examples

m <- matrix(c(1, 2,  
              3, 4), nrow = 2, ncol = 2, byrow = TRUE, 
            dimnames = list(c("a -> b", "c -> d"), c("f [e]", "h [g]")))
m
arrow_to_from_byname(m)
arrow_to_from_byname(m, margin = 2) # No changes expected.
from_to_arrow_byname(m)
arrow_to_bracket_byname(m)
bracket_to_arrow_byname(m)


MatthewHeun/IEATools documentation built on Feb. 6, 2024, 3:29 p.m.