vectorize_byname: Vectorize a matrix

View source: R/Unary.R

vectorize_bynameR Documentation

Vectorize a matrix

Description

Converts a matrix into a column vector. Each element of the matrix becomes an entry in the column vector, with rows named via the notation argument. Callers may want to transpose the matrix first with transpose_byname().

Usage

vectorize_byname(a, notation)

Arguments

a

The matrix to be vectorized.

notation

A string vector created by notation_vec().

Details

The notation is also applied to rowtype and coltype attributes.

Value

A column vector containing all elements of a, with row names assigned as "rowname sep colname".

Examples

m <- matrix(c(1, 5,
              4, 5),
            nrow = 2, ncol = 2, byrow = TRUE, 
            dimnames = list(c("p1", "p2"), c("i1", "i2"))) %>% 
  setrowtype("Products") %>% setcoltype("Industries")
m
vectorize_byname(m, notation = RCLabels::arrow_notation)
# If a single number is provided, the number will be returned as a 1x1 column vector 
# with some additional attributes.
vectorize_byname(42, notation = RCLabels::arrow_notation)
attributes(vectorize_byname(42, notation = RCLabels::arrow_notation))

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