This function combines different matrices by row names and column names by
performing a 2-dimension full join. Gaps are filled with NA
(default) or
0
(argument na_to_zero
).
multi_merge(..., na_to_zero = FALSE)
one or several matrix
objects.
a logical
value. If TRUE
gaps (i.e. unknown edges) are
coded as 0
. Otherwise they are coded as NA
(default).
A matrix
object.
mat1 <- matrix(rep(1, 9), nrow = 3)
colnames(mat1) <- c("A", "B", "C")
rownames(mat1) <- c("A", "B", "C")
mat2 <- matrix(rep(1, 9), nrow = 3)
colnames(mat2) <- c("D", "E", "F")
rownames(mat2) <- c("D", "E", "F")
mat3 <- matrix(rep(1, 9), nrow = 3)
colnames(mat3) <- c("F", "G", "H")
rownames(mat3) <- c("G", "A", "H")
multi_merge(mat1, mat2, mat3)
#> A B C D E F G H
#> A 1 1 1 NA NA 1 1 1
#> B 1 1 1 NA NA NA NA NA
#> C 1 1 1 NA NA NA NA NA
#> D NA NA NA 1 1 1 NA NA
#> E NA NA NA 1 1 1 NA NA
#> F NA NA NA 1 1 1 NA NA
#> G NA NA NA NA NA 1 1 1
#> H NA NA NA NA NA 1 1 1
multi_merge(mat1, mat2, mat3, na_to_zero = TRUE)
#> A B C D E F G H
#> A 1 1 1 0 0 1 1 1
#> B 1 1 1 0 0 0 0 0
#> C 1 1 1 0 0 0 0 0
#> D 0 0 0 1 1 1 0 0
#> E 0 0 0 1 1 1 0 0
#> F 0 0 0 1 1 1 0 0
#> G 0 0 0 0 0 1 1 1
#> H 0 0 0 0 0 1 1 1