toNamedList: Convert to List with Names Equal to List Elements

View source: R/list.R

toNamedListR Documentation

Convert to List with Names Equal to List Elements

Description

Convert to List with Names Equal to List Elements

Usage

toNamedList(x)

Arguments

x

R object, preferably vector of character

Value

result of calling as.list on x with list element names being set to the elements of x.

Examples

x.vector <- c("Peter", "Paul", "Mary")
x.list <- toNamedList(x.vector)
all(names(x.list) == x.vector)

# You may use toNamedList in a call of lapply in order to get a named result
lapply(toNamedList(x.vector), function(x) sprintf("Hello, %s", x))

# Compare with
lapply(x.vector, function(x) sprintf("Hello, %s", x))


KWB-R/kwb.utils documentation built on April 1, 2024, 7:12 a.m.