| aggregate_to_pref_suff_byname {matsbyname} | R Documentation |
Aggregate a matrix to prefixes or suffixes of row and/or column names
Description
Row and column names are often constructed in the form
prefix_start prefix prefix_end suffix_start suffix suffix_end
and described by a notation vector.
(See notation_vec().)
This function performs aggregation by prefix or suffix according to a notation vector.
Usage
aggregate_to_pref_suff_byname(
a,
aggregation_map = NULL,
keep,
margin = c(1, 2),
notation,
pattern_type = "exact"
)
Arguments
a |
A matrix of list of matrices to be aggregated by prefix or suffix. |
aggregation_map |
See |
keep |
See |
margin |
the dimension over which aggregation is to be performed; |
notation |
See |
pattern_type |
See |
Details
This function is a convenience function, as it bundles sequential calls to two helper functions,
rename_to_pref_suff_byname() and aggregate_byname().
All arguments are passed to the helper functions.
Value
An aggregated version of a.
Examples
# This function is superseded.
# Instead, use `aggregate_pieces_byname()`.
# For example:
m <- matrix((1:9), byrow = TRUE, nrow = 3,
dimnames = list(c("r1 -> b", "r2 -> b", "r3 -> a"), c("c1 -> z", "c2 -> y", "c3 -> y")))
m
aggregate_pieces_byname(m, piece = "pref", notation = RCLabels::arrow_notation)
aggregate_pieces_byname(m, piece = "suff", notation = RCLabels::arrow_notation)
# Original examples:
# Aggregation by prefixes does nothing more than rename, because all prefixes are different.
# Doing renaming like this (without also aggregating) is potentially dangerous, because
# some rows and some columns could end up with same names.
aggregate_to_pref_suff_byname(m, keep = "pref", notation = RCLabels::arrow_notation)
# Aggregation by suffix reduces the number of rows and columns,
# because there are same suffixes in both rows and columns
aggregate_to_pref_suff_byname(m, keep = "suff", notation = RCLabels::arrow_notation)