matrix_cols | R Documentation |
It is often helpful to find the columns of a matsindf
data frame that contain exclusively or some matrices.
This function helps with that task.
matrix_cols(.df, .drop_names = FALSE, .any = FALSE)
.df |
The data frame to be queried for matrix columns. |
.drop_names |
A boolean that tells whether to remove the names from
the returned integer vector.
Default is |
.any |
A boolean that tells whether a column is reported when
|
By default, a column is considered a matrix column if all()
of the
rows contain matrices.
Use the .any
argument to modify this behavior.
By default, the vector of integers returned from this function
is named by the columns.
Use the .drop_names
function to modify this behavior.
A vector of integers saying which columns contain matrices.
tidy <- tibble::tibble(matrix = c("V1", "V1", "V1", "V2", "V2"),
row = c("i1", "i1", "i2", "i1", "i2"),
col = c("p1", "p2", "p2", "p1", "p2"),
vals = c(1, 2, 3, 4, 5)) |>
dplyr::mutate(
rowtypes = "Industries",
coltypes = "Products"
) |>
dplyr::group_by(matrix)
matsdf <- tidy |>
collapse_to_matrices(matnames = "matrix", matvals = "vals",
rownames = "row", colnames = "col",
rowtypes = "rowtypes", coltypes = "coltypes")
matsdf
matrix_cols(matsdf)
matrix_cols(matsdf, .drop_names = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.