[R] creating list of lists

Maas James Dr (MED) J.Maas at uea.ac.uk
Sat Mar 12 14:32:47 CET 2011


Question 1:
I have a long list of variable names such as

first <- c("one","two","three")

and what I want to do is create a list of lists ... where the names of each of overall lists components are  "one","two", and "three".

This is the same result as 

second <- list(one=list(),two=list(),three=list())

Is there a way to exploit lapply to convert a list such as first to a list of empty lists such as second?

Question 2:

In a parallel routine using foreach and doMPI have to put calcualted values into a list of lists such as 

list(one=one,
     two=two,
     three=three)

It uses the same (large) list of variable names as first in question 1.  Is there a simpler way to accomplish this with a lapply statement?


I've tried several permutations but no luck! Thanks a bunch.

Jim

===============================
Dr. Jim Maas
University of East Anglia



More information about the R-help mailing list