toNamedList | R Documentation |
Convert to List with Names Equal to List Elements
toNamedList(x)
x |
R object, preferably vector of character |
result of calling as.list
on x
with list element names
being set to the elements of x
.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.