Create Dimension Specs

create_dims(n, d)

Arguments

n

The total number of values

d

The number of dimensions

Value

A d-column row-ordered matrix of possible dimensions or (invisibly) a message if no dimensions can be found.

Examples

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] [,2]
#>  [1,]   13    5
#>  [2,]   12   15
#>  [3,]    5   13
#>  [4,]    6    2
#>  [5,]   15   11
#>  [6,]   15   11
#>  [7,]    4    5
#>  [8,]    6   12
#>  [9,]    9    2
#> [10,]    5    6
#> 

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,]   16    3    7    9
#> [2,]    2   11    6   10
#> 
#> , , 1, 2
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]    2   20    6   19
#> [2,]   17    1    2   14
#> 
#> , , 1, 3
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]    1   18    8   12
#> [2,]   15    5    1   19
#> 
#> , , 1, 4
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]   16    3   10    6
#> [2,]   11    2    3    4
#> 
#> , , 1, 5
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]   10    7   19    8
#> [2,]    1    6    2    1
#> 
#> , , 1, 6
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]    1   12   10    6
#> [2,]    7    9    2    7
#> 
#> , , 1, 7
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]   12    5   19   17
#> [2,]   14    7   12    5
#>