switch_notation_byname: Change row and column name notation

View source: R/notation.R

switch_notation_bynameR Documentation

Change row and column name notation

Description

This function switches matrix row and/or column names from one type of notation to another based on the from and to arguments. Optionally, prefix and suffix can be flipped.

Usage

switch_notation_byname(a, margin = c(1, 2), from, to, flip = FALSE)

Arguments

a

A matrix or list of matrices whose row and/or column notation is to be changed.

margin

1 For rows, 2 for columns, or c(1, 2) for both rows and columns. Default is c(1, 2).

from

The notation to switch away from.

to

The notation to switch to.

flip

A boolean that tells whether to also flip the notation. Default is FALSE.

Value

Matrices with row and column names with switched notation, per arguments.

Examples

m <- matrix(c(1, 2, 
              3, 4), nrow = 2, ncol = 2, byrow = TRUE, 
            dimnames = list(c("b [a]", "d [c]"), c("f [e]", "h [g]"))) %>% 
  setrowtype("Products [Industries]") %>% setcoltype("Industries [Products]")
m
switch_notation_byname(m, from = RCLabels::bracket_notation, to = RCLabels::arrow_notation, 
                       flip = TRUE)
# Also works for lists.
# Note that margin must be specified as a list here.
switch_notation_byname(list(m, m), margin = list(c(1, 2)), 
                       from = RCLabels::bracket_notation, 
                       to = RCLabels::arrow_notation, flip = TRUE)

matsbyname documentation built on Oct. 19, 2023, 5:11 p.m.