Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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]
Name of element(s) to extract from the list elements of xs. What happens is this: x$el1$el2.....

element.value

[any]
If given, vapply is used and this argument is passed to FUN.VALUE. Note that even for repeated indexing (if length(element) > 1) you only pass one value here which refers to the data type of the final result.

simplify

[logical(1) | character(1)]
If FALSE lapply is used, otherwise sapply. If “cols”, we expect the elements to be vectors of the same length and they are arranged as the columns of the resulting matrix. If “rows”, likewise, but rows of the resulting matrix. 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 | simplified vector | matrix]. See above.

Examples

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

BBmisc

Miscellaneous Helper Functions for B. Bischl

v1.11
BSD_2_clause + file LICENSE
Authors
Bernd Bischl [aut, cre], Michel Lang [aut], Jakob Bossek [aut], Daniel Horn [aut], Jakob Richter [aut], Dirk Surmann [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.