list.stack: Stack all list elements to tabular data

Description Usage Arguments Examples

View source: R/list.stack.R

Description

Stack all list elements to tabular data

Usage

1
list.stack(.data, ..., data.table = FALSE)

Arguments

.data

list of vectors, lists, data.frames or data.tables.

...

additional parameters passed to data.table::rbindlist.

data.table

TRUE to keep the result as data.table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
x <- lapply(1:3, function(i) { list(a=i,b=i^2) })
list.stack(x)

x <- lapply(1:3, function(i) { list(a=i,b=i^2,c=letters[i])})
list.stack(x)

x <- lapply(1:3, function(i) { data.frame(a=i,b=i^2,c=letters[i]) })
list.stack(x)

x <- lapply(1:3, function(i) { data.frame(a=c(i,i+1), b=c(i^2,i^2+1))})
list.stack(x)

## End(Not run)

Example output

  a b
1 1 1
2 2 4
3 3 9
  a b c
1 1 1 a
2 2 4 b
3 3 9 c
  a b c
1 1 1 a
2 2 4 b
3 3 9 c
  a  b
1 1  1
2 2  2
3 2  4
4 3  5
5 3  9
6 4 10

rlist documentation built on Sept. 5, 2021, 5:30 p.m.