iapply.RdReturns an iterator over an array, which iterates over the
array in much the same manner
as the apply function.
iapply(X, MARGIN)The apply iterator.
a <- array(1:8, c(2, 2, 2))
# iterate over all the matrices
it <- iapply(a, 3)
as.list(it)
#> [[1]]
#> [,1] [,2]
#> [1,] 1 3
#> [2,] 2 4
#>
#> [[2]]
#> [,1] [,2]
#> [1,] 5 7
#> [2,] 6 8
#>
# iterate over all the columns of all the matrices
it <- iapply(a, c(2, 3))
as.list(it)
#> [[1]]
#> [1] 1 2
#>
#> [[2]]
#> [1] 3 4
#>
#> [[3]]
#> [1] 5 6
#>
#> [[4]]
#> [1] 7 8
#>
# iterate over all the rows of all the matrices
it <- iapply(a, c(1, 3))
as.list(it)
#> [[1]]
#> [1] 1 3
#>
#> [[2]]
#> [1] 2 4
#>
#> [[3]]
#> [1] 5 7
#>
#> [[4]]
#> [1] 6 8
#>