list_unlister: Unlists Columns of Lists by Combinations of Values

Description Usage Arguments Value Author(s) References Examples

View source: R/list_unlister.R

Description

Unlists columns of lists by row creating combinations of values in the process.

Usage

1
list_unlister(indt, addRN = TRUE)

Arguments

indt

The input data.table. The input can also be a list, possibly with elements of different lengths.

addRN

Logical. Should a column named "rn" be added to the data.table? Such a column is required, so if it does not already exist, it is suggested to keep this set to TRUE, the default.

Value

A data.table.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/q/23217958/1270695

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
L1 <- list(list("A", c("B", "C")), list(1:2, 1:3))
list_unlister(L1)

## Note the NULLs and the shorter length of the first list item
L2 <- list(V1 = list("A", c("A", "B"), "X", NULL),
V2 = list(1, c(1, 2, 3), c(1, 2), c(1, 2, 3, 4), 1),
V3 = list(c("a", "b"), "c", "d", c("e", "f"), c("g", "h", "i")))
list_unlister(L2)

DT <- data.table::data.table(
x1 = list("A", c("A", "B"), "X", NULL, c("Z", "W")),
x2 = list(1, c(1, 2, 3), c(1, 2), c(1, 2, 3, 4), 1),
x3 = list(c("a", "b"), "c", "d", c("e", "f"), c("g", "h", "i")))
list_unlister(DT)

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.