ListExtract: Extract named elements from a nested list

Description Usage Arguments Examples

View source: R/format-list.R

Description

Given a list of lists, this function goes through each element and copies the named element from each sub-list into a top-level element of a new list.

Usage

1
ListExtract(list, name, name.elements = TRUE)

Arguments

list

List to be reformatted

name

Quoted name of sub-list item to extract

name.elements

Whether to name the new list elements based on the sub-list item's name and their order in the original list; defaults to TRUE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Create and view a nested list
a <- list(letter = 'a', number = 1)
b <- list(letter = 'b', number = 2)
c <- list(letter = 'c', number = 3)
(nested <- list(first = a, second = b, third = c))

# Extract the letter element
ListExtract(nested, 'letter')

# Extract the number element
ListExtract(nested, 'number')

# Extract the number element into an unnamed list
ListExtract(nested, 'number', FALSE)

phively/wranglR documentation built on April 11, 2020, 5:12 a.m.