Is there a function in base R or a package which takes a list as argument and returns this list with the names set to the list items? Something along these lines:
named.list <- function(l) { names(l) <- l; l }
This is useful for the l?ply
functions in plyr
-- these functions keep the names of the argument list. Compare:
llply(c('a', 'b', 'c'), function(x) paste0('(', x, ')'))
[[1]] [1] "(a)" [[2]] [1] "(b)" [[3]] [1] "(c)"
llply(named.list(c('a', 'b', 'c')), function(x) paste0('(', x, ')'))
$a [1] "(a)" $b [1] "(b)" $c [1] "(c)"