I am trying to populate a matrix with values from a vector, where the name of each value is a combination of the matrix' col- and row names.
set.seed(1001)
mat <- matrix(nrow = 2, ncol = 3, dimnames = list(c("one", "two"), c("house", "tree", "flower")))
vec <- sample.int(10, 5)
names(vec) <- c("one_house", "one_flower", "two_tree", "two_house", "one_tree")
The output I'm looking for is this:
matrix(c(4, 7, 6, 2, 3, NA), nrow = 2, ncol = 3, dimnames = list(c("one", "two"), c("house", "tree", "flower")))
Any help with this would be greatly appreciated.