View source: R/extract_by_name.R
extract_by_name | R Documentation |
This function takes a list and a name, and recursively returns all elements
in the list that have a name matching the provided name. The matching is done
using the grepl
function with fixed = TRUE
, which means that the name is
matched exactly, without any regular expressions.
extract_by_name(x, name)
x |
A list from which to extract elements. |
name |
The name of the elements to extract. |
The function first unlists the input list using the unlist
function. It then uses the grepl
function to find all elements in the list
that have a name matching the provided name. The fixed = TRUE
argument to
grepl
means that the name is matched exactly, without any regular
expressions. The matching elements are then returned as a vector.
A vector of elements from the list that have a name matching the provided name.
list_data <- list(a = 1, b = 2, c = 3, d = 4)
extract_by_name(list_data, "a") # returns 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.