Reorder {s2dv}R Documentation

Reorder the dimension of an array

Description

Reorder the dimensions of a multi-dimensional array. The order can be provided either as indices or the dimension names. If the order is dimension name, the function looks for names(dim(x)). If it doesn't exist, the function checks if attributes "dimensions" exists; this attribute is in the objects generated by Load().

Usage

Reorder(data, order)

Arguments

data

An array of which the dimensions to be reordered.

order

A vector of indices or character strings indicating the new order of the dimensions.

Value

An array which has the same values as parameter 'data' but with different dimension order.

Examples

 dat1 <- array(c(1:30), dim = c(dat = 1, sdate = 3, ftime = 2, lon = 5))
 print(dim(Reorder(dat1, c(2, 1, 4, 3))))
 print(dim(Reorder(dat1, c('sdate', 'dat', 'lon', 'ftime'))))
 dat2 <- array(c(1:10), dim = c(2, 1, 5))
 print(dim(Reorder(dat2, c(2, 1, 3))))
 attr(dat2, 'dimensions') <- c('sdate', 'time', 'region')
 dat2_reorder <- Reorder(dat2, c('time', 'sdate', 'region'))
 # A character array
 dat3 <- array(paste0('a', 1:24), dim = c(b = 2, c = 3, d = 4))
 dat3_reorder <- Reorder(dat3, c('d', 'c', 'b'))

[Package s2dv version 2.0.0 Index]