Learn R Programming

matsindf

Statement of need

Matrices are important mathematical objects, and they often describe networks of flows among nodes. The power of matrices lies in their ability to organize network-wide calculations, thereby simplifying the work of analysts who study entire systems.

But wouldn’t it be nice if there were an easy way to create R data frames whose entries were not numbers but entire matrices? If that were possible, matrix algebra could be performed on columns of similar matrices.

That’s the reason for matsindf. It provides functions to convert a suitably-formatted tidy data frame into a data frame containing a column of matrices.

Furthermore, matsbyname is a sister package that

  • provides matrix algebra functions that respect names of matrix rows and columns (dimnames in R) to free the analyst from the task of aligning rows and columns of operands (matrices) passed to matrix algebra functions and
  • allows matrix algebra to be conducted within data frames using dplyr, tidyr, and other tidyverse functions.

When used together, matsindf and matsbyname allow analysts to wield simultaneously the power of both matrix mathematics and tidyverse functional programming.

Installation

You can install matsindf from CRAN with:

install.packages("matsindf")

You can install a recent development version of matsindf from github with:

# install devtools if not already installed
# install.packages("devtools")
devtools::install_github("MatthewHeun/matsindf")
# To build vignettes locally, use
devtools::install_github("MatthewHeun/matsindf", build_vignettes = TRUE)

History

The functions in this package were used in Heun et al. (2018).

More Information

Find more information, including vignettes and function documentation, at https://MatthewHeun.github.io/matsindf/.

References

Heun, Matthew Kuperus, Anne Owen, and Paul E. Brockway. 2018. “A Physical Supply-Use Table Framework for Energy Analysis on the Energy Conversion Chain.” Applied Energy 226 (September): 1134–62. https://doi.org/10.1016/j.apenergy.2018.05.109.

Copy Link

Version

Install

install.packages('matsindf')

Monthly Downloads

493

Version

0.4.11

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Matthew Heun

Last Published

November 17th, 2025

Functions in matsindf (0.4.11)

should_unlist

Tell whether a column can be unlisted
verify_cols_missing

Verify that column names in a data frame are not already present
write_mats_to_excel

Write matrices to an Excel file
rowcolval_to_mat

Collapse a tidy data frame into a matrix with named rows and columns
:=

Pipe operator
where_to_get_args

Decide where to get each argument to FUN
%>%

Pipe operator
add_UKEnergy2000_matnames

Add a column of matrix names to tidy data frame
df_to_msg

Create a message from a data frame
everything_except

Get symbols for all columns except ...
UKEnergy2000

Energy consumption in the UK in 2000
add_UKEnergy2000_row_col_meta

Add row, column, row type, and column type metadata
build_keep_args

Build a list of arguments to keep
collapse_to_matrices

Collapse a "tidy" data frame to matrices in a data frame (matsindf)
build_matsindf_apply_data_frame

Create a data frame consisting of the input data for matsindf_apply()
check_worksheet_name_violations

Develop a warning message for malformed Excel worksheet names
mat_to_rowcolval

Convert a matrix to a data frame with rows, columns, and values.
handle_null_args

Gracefully handle NULL arguments
matrix_cols

Find columns that contain matrices
expand_to_tidy

Expand a matsindf data frame
matsindf_apply_types

Determine types of .dat and ... arguments for matsindf_apply()
handle_empty_data

Gracefully handle empty data
matsindf_apply

Apply a function to a matsindf data frame (and more)
get_useable_default_args

Create a usable list of default arguments to a function
.data

Data pronoun
index_column

Index a column in a data frame by groups relative to an initial year
group_by_everything_except

Group by all variables except some