split_along_dim.Rd
Split Multidimeninal array to a list along a specified dimension
split_along_dim(a, n)
a | array |
---|---|
n | dimention of array to split |
List of array of 1 less dimension than a
https://stackoverflow.com/questions/20198751/three-dimensional-array-to-list
a <- array(1:prod(4:6), dim=4:6) split_along_dim(a, 3)#> [[1]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 1 5 9 13 17 #> [2,] 2 6 10 14 18 #> [3,] 3 7 11 15 19 #> [4,] 4 8 12 16 20 #> #> [[2]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 21 25 29 33 37 #> [2,] 22 26 30 34 38 #> [3,] 23 27 31 35 39 #> [4,] 24 28 32 36 40 #> #> [[3]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 41 45 49 53 57 #> [2,] 42 46 50 54 58 #> [3,] 43 47 51 55 59 #> [4,] 44 48 52 56 60 #> #> [[4]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 61 65 69 73 77 #> [2,] 62 66 70 74 78 #> [3,] 63 67 71 75 79 #> [4,] 64 68 72 76 80 #> #> [[5]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 81 85 89 93 97 #> [2,] 82 86 90 94 98 #> [3,] 83 87 91 95 99 #> [4,] 84 88 92 96 100 #> #> [[6]] #> [,1] [,2] [,3] [,4] [,5] #> [1,] 101 105 109 113 117 #> [2,] 102 106 110 114 118 #> [3,] 103 107 111 115 119 #> [4,] 104 108 112 116 120 #>