list.transpose: Transpose a nested list.

Description Usage Arguments Details Value Examples

Description

Taken from https://rdrr.io/cran/stackoverflow/src/R/tlist.R. I prefer to copy a short bit of code than to add a dependency.

Usage

1

Arguments

x

[list] The list to be transposed.

Details

R's t function does not have a method for lists. This pretty little piece of code is effectively that. Say you have a list with three sublists, each containg a vector of ten elements. The three sublists are languages, and the ten elements are words in those languages. Functions from the apply family only let you loop through languages and with each iteration you have access to all the words from the given language, but only from that language. list.transpose turns such a list into a list of ten sublists, each containing a vector with three elements – so you can loop through words, and have in each iteration access to word nr 1 from all three languages, then word nr 2, and so on.

Value

[list] The transposed list.

Examples

1
soundcorrs:::list.transpose (list (1:3, 4:6, 7:9))

soundcorrs documentation built on Nov. 16, 2020, 5:09 p.m.