Learn R Programming

hesim (version 0.5.0)

as_array3: Convert between 2D tabular objects and 3D arrays

Description

Convert a 2-dimensional tabular object where each row stores a flattened square matrix to a 3-dimensional array of square matrices and vice versa. This allows multiple transition matrices to be stored as either tabular objects (e.g., matrices, data frames, etc) or as arrays.

Usage

as_array3(x)

as_tbl2(x, output = c("data.table", "data.frame", "matrix", "tpmatrix"))

Arguments

x

For as_array3() a 2-dimensional tabular object where each row stores a flattened square matrix ordered rowwise. Reasonable classes are matrix, data.frame, data.table, and tpmatrix. For as_tbl2() a 3-dimensional array where each slice is a square matrix.

output

The class of the object returned by the function. Either a data.table, data.frame, matrix, or tpmatrix.

Value

For as_array3() a 3-dimensional array of square matrices; for as_tbl2() a 2-dimensional tabular object as specified by output.

See Also

tpmatrix

Examples

Run this code
# NOT RUN {
p_12 <- c(.7, .6)
pmat <- tpmatrix(
 C, p_12,
 0, 1
)
pmat

as_array3(pmat)
as_array3(as.matrix(pmat))
as_tbl2(as_array3(pmat))
# }

Run the code above in your browser using DataLab