v <- matrix(1:10, ncol = 1, dimnames = list(c(paste0("i", 1:10)), c("c1"))) %>%
setrowtype("Industries") %>% setcoltype(NA)
v
hatize_byname(v, keep = "rownames")
r <- matrix(1:5, nrow = 1, dimnames = list(c("r1"), c(paste0("c", 1:5)))) %>%
setrowtype(NA) %>% setcoltype("Commodities")
r
hatize_byname(r, keep = "colnames")
# This also works with lists.
hatize_byname(list(v, v), keep = "rownames")
# A 1x1 column vector is a degenerate case.
# Row names and rowtype are transferred to the column.
matrix(42, nrow = 1, ncol = 1, dimnames = list("r1")) %>%
setrowtype("Product -> Industry") %>%
hatize_byname(keep = "rownames")
# A 1x1 row vector is a degenerate case.
# Column names and coltype are transferred to the row.
matrix(42, nrow = 1, ncol = 1, dimnames = list(NULL, "c1")) %>%
setcoltype("Industry -> Product") %>%
hatize_byname(keep = "colnames")
# A 1x1 matrix with both row and column names generates a failure.
if (FALSE) {
matrix(42, nrow = 1, ncol = 1, dimnames = list("r1", "c1")) %>%
setrowtype("Product -> Industry") %>%
setcoltype("Industry -> Product") %>%
hatize_byname()
}
# But you could specify which you want keep, row names or column names.
m <- matrix(42, nrow = 1, ncol = 1, dimnames = list("r1", "c1")) %>%
setrowtype("Product -> Industry") %>%
setcoltype("Industry -> Product")
m
m %>%
hatize_byname(keep = "rownames")
m %>%
hatize_byname(keep = "colnames")
Run the code above in your browser using DataLab