reverse.list.hierarchy: Reverse the Hierarchy of a List

View source: R/CodeAndRoll2.R

reverse.list.hierarchyR Documentation

Reverse the Hierarchy of a List

Description

This function reverses the hierarchy of a given, 2 level, nested list. The function will ensure that all lists at the same level have the same names, and then transpose the structure, creating a new list for each unique name. Any missing elements in the original lists are not included in the final output. The result is a list where the top-level names are derived from the unique names found at the lower levels of the input list.

Usage

reverse.list.hierarchy(list_of_lists)

Arguments

list_of_lists

A list where some or all elements are themselves lists. The hierarchy of this list will be reversed.

Value

A list with the elements of the original list in reversed order.

Source

https://stackoverflow.com/a/15263737

Examples

list_of_lists <- list("z1" = list(a = 1, b = 2), "z2" = list(b = 4, a = 1, c = 0))
reverse.list.hierarchy(list_of_lists)


vertesy/CodeAndRoll2 documentation built on Nov. 20, 2024, 5:23 a.m.