我有一个具有相对较大的行名和列名的空白矩阵(6000乘以200).然后,我有多个矩阵,它们表示这个矩阵的子集(通常大约是1500乘以120),还包含行名和列名.我想根据行/列名的组合将给定子集中单元格的信息插入到空白矩阵中.
以下是数据和所需输出的示例:
adj1 <- matrix(0, 3, 4)
colnames(adj1) <- c("g1", "g2", "g3", "g4")
rownames(adj1) <- c("Tim", "John", "Sarah")
adj2 <- matrix(0, 2, 2)
colnames(adj2) <- c("g1", "g4")
rownames(adj2) <- c("Tim", "John")
adj2[1,2] <- 1
adj2
combined_adj <- matrix(0,3,4)
colnames(combined_adj) <- c("g1","g2","g3","g4")
rownames(combined_adj) <- c("Tim","John", "Sarah")
combined_adj[1,4] <- 1
combined_adj
我在某种程度上设法通过列名进行了交集,但不是通过行/列名称的确切组合.