array2: Make or reshape an array with C-style (row-major) semantics

Description Usage Arguments Details Examples

View source: R/dim2.R

Description

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).

Usage

1
2
3
4
5
6
7
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

1
2
3
4
5
6
array(1:4, c(2,2))
array2(1:4, c(2,2))

# for a drop-in replacement to reticulate::array_reshape
array_reshape <- listarrays:::array_reshape
array_reshape(1:4, c(2,2))

listarrays documentation built on March 26, 2020, 6:10 p.m.