splitArray: Splits an array along a given dimension

Description Usage Arguments Value Examples

View source: R/array_transform.R

Description

splitArray splits an array along given dimension(s) into a list of sub-arrays

Usage

1
splitArray(dat, whichdim, f = NULL, drop = FALSE)

Arguments

dat

numeric array (preferably with named dimnames)

whichdim

numeric or character vector, the dimension(s) of the array to split along

f

a list of factors in the sense that lapply(f, as.factor) defines the grouping to split along for each dimensions in whichdim. If NULL, splitArray splits all levels of the whichdim dimensions. If not NULL, the length of f must match the length of whichdim. If f is a named list, the names are reflected in the dimnames attribute of the resulting list (see Value section).

drop

logical; should singleton dimensions (dimensions with only one level) be deleted (TRUE) or not (FALSE, the default)

Value

A list of subsets of the original data matrix/array with dim and dimnames attributes. The dimensions of the list correspond to the length of each element in f (after replacing NULL values with correct vectors).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# load example data
data(erps)

# get the reading group membership of the subjects
dat_id <- attr(erps, "id")

# split on the basis of the reading group membership
groups <- splitArray(erps, "id", list(readgroup = dat_id$group))

# check
str(groups)

tdeenes/eegR documentation built on April 19, 2021, 4:17 p.m.