Combines different connectivity matrices by row names and column names by performing a 2-dimensional full join. Missing edges are filled with 0 (default) or NA (argument na_to_zero).

append_matrix(..., na_to_zero = TRUE)

Arguments

...

one or several matrix objects created by connectivity_matrix().

na_to_zero

a logical value. If TRUE (default) missing edges are coded as 0. Otherwise they will be coded as NA.

Value

A connectivity matrix of dimensions n x n, where n is the total number of unique nodes across all provided matrices.

Examples

mat1 <- matrix(rep(1, 9), nrow = 3)
colnames(mat1) <- c("A", "B", "C")
rownames(mat1) <- c("A", "B", "C")
mat1
#>   A B C
#> A 1 1 1
#> B 1 1 1
#> C 1 1 1

mat2 <- matrix(rep(1, 9), nrow = 3)
colnames(mat2) <- c("D", "E", "F")
rownames(mat2) <- c("D", "E", "F")
mat2
#>   D E F
#> D 1 1 1
#> E 1 1 1
#> F 1 1 1

mat3 <- matrix(rep(1, 9), nrow = 3)
colnames(mat3) <- c("F", "G", "H")
rownames(mat3) <- c("F", "G", "H")
mat3
#>   F G H
#> F 1 1 1
#> G 1 1 1
#> H 1 1 1

append_matrix(mat1, mat2, mat3)
#>   A B C D E F G H
#> A 1 1 1 0 0 0 0 0
#> 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 1 1
#> G 0 0 0 0 0 1 1 1
#> H 0 0 0 0 0 1 1 1

append_matrix(mat1, mat2, mat3, na_to_zero = FALSE)
#>    A  B  C  D  E  F  G  H
#> A  1  1  1 NA NA NA NA NA
#> 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  1  1
#> G NA NA NA NA NA  1  1  1
#> H NA NA NA NA NA  1  1  1