Learn R Programming

PAMmisc (version 1.12.3)

squishList: Compress a List by Name

Description

Attempts to compress a list by combining elements with the same name, searching recursively if there are lists in your list

Usage

squishList(myList, unique = FALSE)

Value

a list with one element for every unique name in the original list

Arguments

myList

a list with named elements to be compressed

unique

logical flag to try and reduce result to only unique values

Author

Taiki Sakai taiki.sakai@noaa.gov

Details

items with the same name are assumed to have the same structure and will be combined. Dataframes will be combined with bind_rows, vectors just be collapsed into one vector, matrices will be combined with rbind, lists will be combined recursively with another call to squishList

Examples

Run this code

myList <- list(a=1:3, b=letters[1:4], a=5:6, b=letters[4:10])
squishList(myList)

myList <- list(a=1:3, b=data.frame(x=1:3, y=4:6), b=data.frame(x=10:14, y=1:5))
squishList(myList)

myList <- list(a=list(c=1:2, d=2), b=letters[1:3], a=list(c=4:5, d=6:9))
squishList(myList)

Run the code above in your browser using DataLab