Create Dimension Specs
create_dims(n, d)The total number of values
The number of dimensions
A d-column row-ordered matrix of possible dimensions or (invisibly) a message if no dimensions can be found.
k <- create_dims(n = 20, d = 3)
# Create an array with dimensions sampled from `k`:
array(sample(x = 20, size = prod(k[1, ]), replace = TRUE), dim = k[sample(nrow(k), 1), ])
#> , , 1
#>
#> [,1]
#> [1,] 12
#> [2,] 12
#> [3,] 14
#> [4,] 7
#>
#> , , 2
#>
#> [,1]
#> [1,] 1
#> [2,] 15
#> [3,] 5
#> [4,] 19
#>
#> , , 3
#>
#> [,1]
#> [1,] 1
#> [2,] 12
#> [3,] 15
#> [4,] 14
#>
#> , , 4
#>
#> [,1]
#> [1,] 14
#> [2,] 4
#> [3,] 1
#> [4,] 7
#>
#> , , 5
#>
#> [,1]
#> [1,] 9
#> [2,] 3
#> [3,] 7
#> [4,] 20
#>
k <- create_dims(n = 56, d = 4)
# Create an array with dimensions sampled from `k`:
array(sample(x = 20, size = prod(k[1, ]), replace = TRUE), dim = k[sample(nrow(k), 1), ])
#> , , 1, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 2 9 1 13
#>
#> , , 2, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 13 10 15 7
#>
#> , , 3, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 12 3 9 6
#>
#> , , 4, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 5 7 19 18
#>
#> , , 5, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 8 10 3 11
#>
#> , , 6, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 19 11 1 17
#>
#> , , 7, 1
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 6 14 1 6
#>
#> , , 1, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 18 13 12 8
#>
#> , , 2, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 6 15 6 6
#>
#> , , 3, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 18 10 3 19
#>
#> , , 4, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 1 3 17 6
#>
#> , , 5, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 10 7 15 18
#>
#> , , 6, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 17 13 17 15
#>
#> , , 7, 2
#>
#> [,1] [,2] [,3] [,4]
#> [1,] 15 12 8 7
#>