Skip to contents

Merge List of Named Arrays

Usage

mergeNamedArrays(x, check_dim = TRUE)

Arguments

x

list of arrays of the same dimension

check_dim

logical. If TRUE, it is checked whether the source dimension names are available in the target dimension names

Examples

a1 <- array(
  1:12,
  dim = c(2, 4, 2),
  dimnames = list(paste0("x", 1:2), paste0("y", 1:4), paste0("z", 1:2))
)

a2 <- array(
  11:16,
  dim = c(1, 3, 2),
  dimnames = list("x3", paste0("y", 2:4), paste0("z", 1:2))
)

mergeNamedArrays(list(a1, a2))
#> , , z1
#> 
#>    y1 y2 y3 y4
#> x1  1  3  5  7
#> x2  2  4  6  8
#> x3 NA 11 12 13
#> 
#> , , z2
#> 
#>    y1 y2 y3 y4
#> x1  9 11  1  3
#> x2 10 12  2  4
#> x3 NA 14 15 16
#>