Constructor for building rray objects. Existing vectors, matrices, and arrays can be used to build the rray, but their dimension names are not retained.
rray(x = numeric(0), dim = NULL, dim_names = NULL)
x | A numeric vector, matrix, or array to convert to an rray. |
---|---|
dim | An integer vector describing the dimensions of the rray. If |
dim_names | A list. For no names, |
An rray.
The dim
argument is very flexible.
If vec_size(x) == prod(dim)
, then a reshape is performed.
Otherwise broadcasting is attempted.
This allows quick construction of a wide variety of structures. See the example section for more.
rray objects are never reduced to vectors when subsetting using [
(i.e.
dimensions are never dropped).
#> <rray<dbl>[3]> #> [1] 1 2 3#> <rray<dbl>[,4][3]> #> [,1] [,2] [,3] [,4] #> [1,] 1 1 1 1 #> [2,] 2 2 2 2 #> [3,] 3 3 3 3#> <rray<dbl>[,2,4][3]> #> , , 1 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #> #> , , 2 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #> #> , , 3 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #> #> , , 4 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #>#> <rray<dbl>[,2][2]> #> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4#> <rray<dbl>[,2,3][2]> #> , , 1 #> #> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4 #> #> , , 2 #> #> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4 #> #> , , 3 #> #> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4 #>#> <rray<dbl>[,4][1]> #> [,1] [,2] [,3] [,4] #> [1,] 1 2 3 4#> <rray<dbl>[,2,2][3]> #> , , 1 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #> #> , , 2 #> #> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1 #> [3,] 1 1 #>#> <rray<dbl>[,2][3]> #> [,1] [,2] #> x 1 1 #> y 2 2 #> z 3 3