flatten: Flatten a List or Other Object

Description Usage Arguments Details Value Examples

View source: R/flatten.R

Description

Reduces the depth of a list or other object. Most non-atomic objects (matrix, data.frame, environments, etc.) are converted to a "list" in the first level flattening. Atomic vectors, functions, and other special objects return themselves.

Usage

1
flatten(x, level = -1, ...)

Arguments

x

object of any class, but primarily designed for lists and other "deep" objects

level

numeric integer describing the depth at which to flatten the object. If level < 0, the object will become as flat as possible.

...

objects passed to methods

Details

flatten maps itself to each object with the aggregate x, combining the results. Each time it is mapped, the level is reduced by 1. When level == 0, or an atomic vector or other special object is reached, flatten returns the object without mapping itself.

Value

flatter object

Examples

1
2
3
4
5
6
x <- list(a = 1, b = 2:5, c = list(list(1,2,3), 4, 5), 6)
flatten(x)
## returns: [1 2 3 4 5 1 2 3 4 5 6]

flatten(x, level=1)
## returns: [1 2 3 4 5 [1 2 3] 4 5 6]

eList documentation built on Jan. 23, 2021, 1:05 a.m.