rename_to_piece_byname | R Documentation |
It can be convenient to rename rows or columns of matrices based on retaining only a piece of the row and/or column names. This function provides that capability.
rename_to_piece_byname(
a,
piece,
margin = list(c(1, 2)),
inf_notation = TRUE,
notation = list(RCLabels::notations_list),
choose_most_specific = FALSE,
prepositions = list(RCLabels::prepositions_list)
)
a |
A matrix or list of matrices whose rows or columns will be renamed. |
piece |
A character string indicating which piece of the row or column names to retain, one of "noun", "pps", "pref" or "suff", or a preposition, indicating which part of the row or column name is to be retained. |
margin |
As a character, the row type or column type to be renamed.
As an integer, the margin to be renamed.
Default is |
inf_notation |
A boolean that tells whether to infer notation.
Default is |
notation |
The notation used for row and column labels.
Default is |
choose_most_specific |
A boolean that indicates whether the most-specific notation
will be inferred when more than one of |
prepositions |
Prepositions that can be used in the row and column label.
Default is |
Internally, this function finds pieces of row and column names
via the RCLabels
package.
piece
can be anything that RCLabels::get_piece()
understands.
Note that margin
can be either an integer vector or
a character vector.
If margin
is a character vector,
it is interpreted as a row or column type, and
margin_from_types_byname()
is called internally to
resolve the integer margins of interest.
Note that if row and/or column type are present,
the row and/or column type are also renamed according to piece
.
A version of a
with renamed rows and columns.
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
rename_to_piece_byname(m, piece = "pref", notation = RCLabels::arrow_notation)
m2 <- m %>%
setrowtype("rows") %>% setcoltype("cols")
m2
rename_to_piece_byname(m2, piece = "pref", margin = "rows",
notation = RCLabels::arrow_notation)
rename_to_piece_byname(m2, piece = "suff", margin = "rows",
notation = RCLabels::arrow_notation)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.