a <- matrix(42, nrow = 3, ncol = 5,
dimnames = list(c("Electricity [from b in c]",
"Coal [from e in f]",
"Crude oil [from Production in USA]"),
c("Main activity producer electricity plants",
"Wind turbines",
"Oil refineries",
"Coal mines",
"Automobiles"))) %>%
setrowtype("Product") %>% setcoltype("Industry")
a
v <- matrix(1:7, nrow = 7, ncol = 1,
dimnames = list(c("Electricity",
"Peat",
"Hydro",
"Crude oil",
"Coal",
"Hard coal (if no detail)",
"Brown coal"),
"phi")) %>%
setrowtype("Product") %>% setcoltype("phi")
v
vec_from_store_byname(a, v, a_piece = "pref")
vec_from_store_byname(a, v, a_piece = "noun")
v2 <- matrix(1:7, nrow = 7, ncol = 1,
dimnames = list(c("Electricity",
"Peat",
"USA",
"c",
"Coal",
"Hard coal (if no detail)",
"f"),
"phi")) %>%
setrowtype("Product") %>% setcoltype("phi")
vec_from_store_byname(a, v2, a_piece = "in")
# Works with lists
v3 <- matrix(1:7, nrow = 7, ncol = 1,
dimnames = list(c("Electricity [from USA]",
"Peat [from nowhere]",
"Production [from GHA]",
"e [from ZAF]",
"Coal [from AUS]",
"Hard coal (if no detail) [from GBR]",
"b [from Nebraska]"),
"phi")) %>%
setrowtype("Product") %>% setcoltype("phi")
a_list <- list(a, a)
v_list <- list(v3, v3)
vec_from_store_byname(a_list, v_list, a_piece = "in", v_piece = "from")
# Also works in a data frame
df <- tibble::tibble(a = list(a, a, a),
v = list(v3, v3, v3))
df %>%
dplyr::mutate(
actual = vec_from_store_byname(a = a, v = v, a_piece = "in", v_piece = "from")
)
Run the code above in your browser using DataLab