Learn R Programming

rgp (version 0.4-1)

splitList: Splitting and grouping of lists

Description

Functions for splitting and grouping lists into sublists. splitList splits a list l into max(groupAssignment) groups. The integer indices of groupAssignment determine in which group each element of l goes. groupListConsecutive splits l into numberOfGroups consecutive sublists (or groups). groupListDistributed distributes l into numberOfGroups sublists (or groups). flatten flattens a list l of lists into a flat list by concatenation. If recursive is TRUE (defaults to FALSE), flatten will be recursively called on each argument first. intersperse joins two lists xs and ys into a list of pairs containig every possible pair, i.e. intersperse(xs, ys) equals the product list of xs and ys. The pairConstructor parameter can be used to change the type of pairs returned.

Usage

splitList(l, groupAssignment)
groupListConsecutive(l, numberOfGroups)
groupListDistributed(l, numberOfGroups)
flatten(l, recursive = FALSE)
intersperse(xs, ys, pairConstructor = list)

Arguments

l
A list.
xs
A list.
ys
A list.
pairConstructor
The function to use for constructing pairs, defaults to list.
groupAssignment
A vector of group assignment indices.
numberOfGroups
The number of groups to create, must be
recursive
Whether to operate recursively on sublists or vectors.

Value

A list of lists, where each member represents a group.