Description Usage Arguments Details Value Examples
Provides a convenient mechanism for expanding the dimensions of a matrix with a specified default value. This is particularly useful if the matrix needs to match dimensions with another matrix. Expand can take either another matrix or a set of dimnames to grow the matrix. In either case, the expanded matrix will have dimensions that match the explicitly or implicitly specified dimnames.
1 | expand(m, target, default = 0)
|
m |
A matrix to expand |
target |
A list containing the dimnames or a matrix that contains dimnames |
default |
The default value to use for the new entries |
To properly expand m
to target, the rownames and colnames of
m
must be a strict subset of target's rownames and colnames.
If this requirement is not
satisfied, the behavior is currently undefined (although most likely an
error will result). In the future, the behavior might be configurable to
drop those rows/columns that are not in target's rownames/colnames.
In general, expand
tries to err on the side of accomodation,
although the implementation is incomplete. If target is a list, then
the format is the same as when constructing a matrix and passing
dimnames as an argument. Currently, only a list or a matrix are supported.
If a list, target[[0]] represent the row names and target[[1]] are
the column names.
This could be relaxed in the future to any object that has a rownames
and colnames.
Note that a current limitation/feature in expand is that it orders the resulting matrix by rows and columns. More precise control needs to be provided here, with the default being the ordering of the rows and columns conforming to target.
TODO: Consistency check to ensure all rownames/colnames of m are a subset of target
The expanded matrix with rows and columns corresponding to the target dimnames
1 2 3 4 5 6 7 8 |
col.1 col.2 col.3
row.1 1 2 0
row.2 4 5 0
row.3 7 8 0
row.4 0 0 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.