list_of_rows_or_cols: Named list of rows or columns of matrices

View source: R/Utilities.R

list_of_rows_or_colsR Documentation

Named list of rows or columns of matrices

Description

This function takes matrix m and converts it to a list of single-row (if margin == 1) or single-column(if margin == 2) matrices. Each item in the list is named for its row (if margin == 1) or column (if margin == 2).

Usage

list_of_rows_or_cols(a, margin)

Arguments

a

a matrix or list of matrices (say, from a column of a data frame)

margin

the margin of the matrices to be extracted (1 for rows, 2 for columns)

Details

Note that the result provides column vectors, regardless of the value of margin.

Value

a named list of rows or columns extracted from m

Examples

m <- matrix(data = c(1:6), 
            nrow = 2, ncol = 3, 
            dimnames = list(c("p1", "p2"), c("i1", "i2", "i3"))) %>%
  setrowtype(rowtype = "Products") %>% setcoltype(coltype = "Industries")
list_of_rows_or_cols(m, margin = 1)
list_of_rows_or_cols(m, margin = 2)

matsbyname documentation built on April 2, 2022, 1:06 a.m.