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)
Run the code above in your browser using DataLab