Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

splitter_a

Split an array by .margins.


Description

Split a 2d or higher data structure into lower-d pieces based

Usage

splitter_a(data, .margins = 1L, .expand = TRUE, .id = NA)

Arguments

data

>1d data structure (matrix, data.frame or array)

.margins

a vector giving the subscripts to split up data by.

.expand

if splitting a dataframe by row, should output be 1d (expand = FALSE), with an element for each row; or nd (expand = TRUE), with a dimension for each variable.

.id

names of the split label. Pass NULL to avoid creation of split labels. Omit or pass NA to use the default names "X1", "X2", .... Otherwise, this argument must have the same length as .margins.

Details

This is the workhorse of the a*ply functions. Given a >1 d data structure (matrix, array, data.frame), it splits it into pieces based on the subscripts that you supply. Each piece is a lower dimensional slice.

The margins are specified in the same way as apply, but splitter_a just splits up the data, while apply also applies a function and combines the pieces back together. This function also includes enough information to recreate the split from attributes on the list of pieces.

Value

a list of lower-d slices, with attributes that record split details

See Also

Other splitter functions: splitter_d()

Examples

plyr:::splitter_a(mtcars, 1)
plyr:::splitter_a(mtcars, 2)

plyr:::splitter_a(ozone, 2)
plyr:::splitter_a(ozone, 3)
plyr:::splitter_a(ozone, 1:2)

plyr

Tools for Splitting, Applying and Combining Data

v1.8.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.