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

541

Version

0.4.8

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Matthew Heun

Last Published

February 1st, 2024

Functions in matsindf (0.4.8)

group_by_everything_except

Group by all variables except some
get_useable_default_args

Create a usable list of default arguments to a function
%>%

Pipe operator
mat_to_rowcolval

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

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

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

Tell whether a column can be unlisted
handle_null_args

Gracefully handle NULL arguments
:=

Pipe operator
rowcolval_to_mat

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

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

Decide where to get each argument to FUN
verify_cols_missing

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

Collapse a "tidy" data frame to matrices in a data frame matsindf)
everything_except

Get symbols for all columns except ...
build_matsindf_apply_data_frame

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

Add a column of matrix names to tidy data frame
expand_to_tidy

Expand a matsindf data frame
UKEnergy2000

Energy consumption in the UK in 2000
df_to_msg

Create a message from a data frame
build_keep_args

Build a list of arguments to keep
.data

Data pronoun
add_UKEnergy2000_row_col_meta

Add row, column, row type, and column type metadata
handle_empty_data

Gracefully handle empty data
matrix_cols

Find columns that contain matrices