ArrayToList: Split an array into list by a given array dimension

Description Usage Arguments Value See Also Examples

View source: R/ArrayToList.R

Description

This function splits an array into a list as required by PlotLayout function from package "s2dv" when parameter 'special_args' is used. The function ArrayToList allows to add names to the elements of the list in two different levels, the 'list' or the 'sublist'.

Usage

1
ArrayToList(data, dim, level = "list", names = NULL)

Arguments

data

A multidimensional array.

dim

A character string indicating the name of the dimension to split or an integer indicating the position of the dimension.

level

A string character 'list' or 'sublist' indicating if it should be a list or a sublist. By default it creates a list.

names

A vector of character strings to name the list (if it is a single string, it would be reused) or a single character string to name the elements in the sublist.

Value

A list of arrays of the length of the dimension set in parameter 'dim'.

See Also

PlotLayout

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
data <- array(1:240, c(month = 12, member = 5, time = 4))
# Create a list:
datalist <- ArrayToList(data, dim = 'month', level = 'list', names = month.name)
class(datalist)
class(datalist[[1]])
str(datalist)
# Create a sublist:
datalist <- ArrayToList(data, dim = 'month', level = 'sublist', names = 'dots')
class(datalist)
class(datalist[[1]])
class(datalist[[1]][[1]])
str(datalist)

ClimProjDiags documentation built on Nov. 3, 2021, 5:07 p.m.