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

t_list

Efficient List Transpose


Description

t_list turns a list of lists inside-out. The performance is quite efficient regardless of the size of the list.

Usage

t_list(l)

Arguments

l

a list of lists. Elements inside the sublists can be heterogenous, including further lists.

Value

l transposed such that the second layer of the list becomes the top layer and the top layer the second layer. See Examples.

See Also

Examples

# Homogenous list of lists
l <- list(a = list(c = 1, d = 2), b = list(c = 3, d = 4))
str(l)
str(t_list(l))

# Heterogenous case
l2 <- list(a = list(c = 1, d = letters), b = list(c = 3:10, d = list(4, e = 5)))
attr(l2, "bla") <- "abc"  # Attributes other than names are preserved
str(l2)
str(t_list(l2))

rm(l, l2)

collapse

Advanced and Fast Data Transformation

v1.5.3
GPL (>= 2) | file LICENSE
Authors
Sebastian Krantz [aut, cre], Matt Dowle [ctb], Arun Srinivasan [ctb], Laurent Berge [ctb], Dirk Eddelbuettel [ctb], Josh Pasek [ctb], Kevin Tappe [ctb], R Core Team and contributors worldwide [ctb], Martyn Plummer [cph], 1999-2016 The R Core Team [cph]
Initial release
2021-03-05

We don't support your browser anymore

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