These functions reshape or make an array using C-style, row-major semantics. The returned array is still R's native F-style, (meaning, the underlying vector has been reordered).

array2(data, dim = length(data), dimnames = NULL)

matrix2(...)

dim2(x) <- value

set_dim2(...)

Arguments

data

what to fill the array with

dim

numeric vector of dimensions

dimnames

a list of dimnames, must be the same length as dims

...

passed on to set_dim()

x

object to set dimensions on (array or atomic vector)

value

a numeric (integerish) vector of new dimensions

Details

Other than the C-style semantics, these functions behave identically to their counterparts (array2() behaves identically to array(), `dim2<-`() to `dim<-`()). set_dim2() is just a wrapper around set_dim(..., order = "C").

See examples for a drop-in pure R replacement to reticulate::array_reshape()

Examples

array(1:4, c(2,2))
#> [,1] [,2] #> [1,] 1 3 #> [2,] 2 4
array2(1:4, c(2,2))
#> [,1] [,2] #> [1,] 1 2 #> [2,] 3 4
# for a drop-in replacement to reticulate::array_reshape array_reshape <- listarrays:::array_reshape array_reshape(1:4, c(2,2))
#> [,1] [,2] #> [1,] 1 2 #> [2,] 3 4