Skip to contents

Transform a list of array with the same structure in a array.

Usage

list_to_array(l, what = "state", check = FALSE)

Arguments

l

list of array

what

character, name of the last dimension. Default to "state".

check

logical, should some tests be made to detect inconsistencies in the structure of arrays.

Value

Array, whose last dimension is made accordingly to length and names of l

Author

Frédéric Grelot, frederic.grelot.1994_cran@m4x.org

Examples


dim_a =  c(3, 3)
dimnames_a = setNames(
    lapply(dim_a, function(x){letters[seq(x)]}),
    sprintf("dim_%s", letters[seq_along(dim_a)])
)
a = array(as.numeric(1), dim = dim_a, dimnames = dimnames_a)
l = list(a1 = a, a2 = 2 * a)

list_to_array(l)
#> , , state = a1
#> 
#>      dim_b
#> dim_a a b c
#>     a 1 1 1
#>     b 1 1 1
#>     c 1 1 1
#> 
#> , , state = a2
#> 
#>      dim_b
#> dim_a a b c
#>     a 2 2 2
#>     b 2 2 2
#>     c 2 2 2
#> 
list_to_array(l, what = "other")
#> , , other = a1
#> 
#>      dim_b
#> dim_a a b c
#>     a 1 1 1
#>     b 1 1 1
#>     c 1 1 1
#> 
#> , , other = a2
#> 
#>      dim_b
#> dim_a a b c
#>     a 2 2 2
#>     b 2 2 2
#>     c 2 2 2
#>