Вы можете извлечь rownames
и colnames
из mat2
и использовать его для заказа mat1
.
mat1[rownames(mat2),colnames(mat2)]
# C2 C1 C4 C3
#R1 2 1 4 3
#R3 10 9 12 11
#R4 14 13 16 15
#R2 6 5 8 7
данные
mat1 <- structure(c(1L, 5L, 9L, 13L, 2L, 6L, 10L, 14L, 3L, 7L, 11L, 15L,
4L, 8L, 12L, 16L), .Dim = c(4L, 4L), .Dimnames = list(c("R1",
"R2", "R3", "R4"), c("C1", "C2", "C3", "C4")))
mat2 <- structure(c("A", "E", "I", "M", "B", "F", "J", "N", "C", "G",
"K", "O", "D", "H", "L", "P"), .Dim = c(4L, 4L), .Dimnames = list(
c("R1", "R3", "R4", "R2"), c("C2", "C1", "C4", "C3")))