R/Utilities.R
rename_to_pref_suff_byname.Rd
It can be convenient to rename rows or columns of matrices based on retaining prefixes or suffixes. This function provides that capability.
rename_to_pref_suff_byname(a, keep, margin = c(1, 2), notation)
a | a matrix or list of matrices whose rows or columns will be renamed. |
---|---|
keep | one of "prefix" or "suffix" indicating which part of the row or column name to retain. |
margin | one of |
notation | See |
a
with potentially different row or column names.
A prefix is defined by an opening string (prefix_open
) and a closing string (prefix_close
).
A suffix is defined by an opening string (suffix_open
) and a closing string (suffix_close
).
If sep
is provided and none of prefix_open
, prefix_close
, suffix_open
, and suffix_close
are provided,
default arguments become:
* prefix_open
: "",
* prefix_close
: sep
,
* suffix_open
: sep
, and
* suffix_close
: "".
The keep
parameter tells which portion to retain (prefixes or suffixes),
If prefixes or suffixes are not found in a row and/or column name, that name is unchanged.
m <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE, dimnames = list(c("a -> b", "r2", "r3"), c("a -> b", "c -> d"))) m#> a -> b c -> d #> a -> b 1 2 #> r2 3 4 #> r3 5 6#> a c #> a 1 2 #> r2 3 4 #> r3 5 6#> b d #> b 1 2 #> r2 3 4 #> r3 5 6