Learn R Programming

BBmisc (version 1.5)

extractSubList: Extracts a named element from a list of lists.

Description

Extracts a named element from a list of lists.

Usage

extractSubList(xs, element, element.value, simplify = TRUE,
  use.names = TRUE)

Arguments

xs
[list] A list of named lists.
element
[character(1)] Name of element to extract from the list elements of xs.
element.value
[any] If given, vapply is used and this argument is passed to FUN.VALUE.
simplify
[logical(1)] If TRUE sapply is used, otherwise lapply. Default is TRUE.
use.names
[logical(1)] If TRUE and xs is named, the result is named as xs, otherwise the result is unnamed. Default is TRUE.

Value

  • [list or simplified vector].

Examples

Run this code
xs = list(list(a=1, b=2), list(a=5, b=7))
extractSubList(xs, "a")
extractSubList(xs, "a", simplify=FALSE)

Run the code above in your browser using DataLab