Is there a way to use mapply on two vectors to construct a named list? The first vector would be of type character
and contain the names used for the list while
I share Ben's puzzlement about why you might want to do this, and his recommendation.
Just for curiosity's sake, there is a sort of "hidden" feature in mapply
that will allow this:
x <- letters[1:2]
y <- 1:2
mapply(function(x,y) { y }, x, y, SIMPLIFY = FALSE,USE.NAMES = TRUE)
$a
[1] 1
$b
[1] 2
Noting that the documentation for USE.NAMES
says:
USE.NAMES logical; use names if the first ... argument has names, or if it is a character vector, use that character vector as the names.