Description Usage Arguments Details Value Examples
Constructor for building rray objects. Existing vectors, matrices, and arrays can be used to build the rray, but their dimension names are not retained.
1 |
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, |
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).
An rray.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 1D rray. Looks like a vector
# functions similar to a 1 column matrix
rray(c(1,2,3), dim = c(3))
# 3 rows, 4 cols
rray(c(1,2,3), dim = c(3, 4))
# 3x2x4 array
rray(1, dim = c(3, 2, 4))
# from a matrix
mat <- matrix(c(1, 2, 3, 4), ncol = 2)
rray(mat)
# from a matrix, with broadcasting
rray(mat, dim = c(2, 2, 3))
# reshape that matrix during creation
# (different from broadcasting)
rray(mat, dim = c(1, 4))
# from an array, with broadcasting
arr <- array(1, c(1, 2, 2))
rray(arr, c(3, 2, 2))
# with row names
rray(c(1, 2, 3), c(3, 2), dim_names = list(c("x", "y", "z"), NULL))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.