margin_from_types_byname | R Documentation |
Converts row and column types to integer margins,
based on a
and types
.
If types
is not a character vector, types
is returned unmodified.
If types
is a character vector, an integer vector is returned
corresponding to the margins on which types
are found.
If types
are not found in the row or column types of a
,
NA_integer_
is returned.
margin_from_types_byname(a, types)
a |
A matrix or list of matrices. |
types |
A character vector or list of character vectors
representing row or column types whose
corresponding integer margins in |
A vector of integers or list of vectors of integers
corresponding to the margins on which types
exist.
# Works for single matrices
m <- matrix(1) %>%
setrowtype("Product") %>% setcoltype("Industry")
margin_from_types_byname(m, "Product")
margin_from_types_byname(m, "Industry")
margin_from_types_byname(m, c("Product", "Industry"))
margin_from_types_byname(m, c("Industry", "Product"))
# Works for lists of matrices
margin_from_types_byname(list(m, m), types = "Product")
margin_from_types_byname(list(m, m), types = "Industry")
margin_from_types_byname(list(m, m), types = c("Product", "Product"))
margin_from_types_byname(list(m, m), types = c("Industry", "Industry"))
margin_from_types_byname(list(m, m), types = c("Product", "Industry"))
margin_from_types_byname(list(m, m), types = list("Product", "Industry"))
margin_from_types_byname(list(m, m), types = list(c("Product", "Industry")))
margin_from_types_byname(list(m, m), types = list(c("Product", "Industry"),
c("Product", "Industry")))
# Works in a data frame
m2 <- matrix(2) %>%
setrowtype("Industry") %>% setcoltype("Product")
df <- tibble::tibble(m = list(m, m2), types = list("Product", c("Product", "Industry")))
res <- df %>%
dplyr::mutate(
margin = margin_from_types_byname(m, types)
)
res$margin
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.