rray_unstack() splits an array along axis and then removes that axis
from each of the resulting arrays. The result is a list of arrays that have
a dimensionality 1 less than x itself.
Using rray_stack() along the same axis reconstructs x.
Arguments
- x
An array.
- ...
These dots are for future extensions and must be empty.
- axis
The axis to unstack along, given by position or by title.
Details
Names along axis become the names of the returned list. Names on the
surviving axes are carried over to their new locations, as are their titles.
Because the dimensionality is reduced by 1, x must have a dimensionality
of at least 2 to begin with.
Examples
x <- array(1:6, c(2, 3))
# One array per row
rray_unstack(x, axis = 1)
#> [[1]]
#> [1] 1 3 5
#>
#> [[2]]
#> [1] 2 4 6
#>
# One array per column
rray_unstack(x, axis = 2)
#> [[1]]
#> [1] 1 2
#>
#> [[2]]
#> [1] 3 4
#>
#> [[3]]
#> [1] 5 6
#>
# One array per column, by title
z <- rray_set_titles(x, c("row", "col"))
rray_unstack(z, axis = "col")
#> [[1]]
#> [1] 1 2
#>
#> [[2]]
#> [1] 3 4
#>
#> [[3]]
#> [1] 5 6
#>
# Names along the axis become list names
y <- array(1:4, c(2, 2), dimnames = list(c("a", "b"), c("x", "y")))
rray_unstack(y, axis = 2)
#> $x
#> a b
#> 1 2
#>
#> $y
#> a b
#> 3 4
#>
# Unstacking and stacking along the same axis are inverses
rray_stack(!!!rray_unstack(x, axis = 2), .axis = 2)
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
