[R] creating list of lists
Ben Tupper
btupper at bigelow.org
Sat Mar 12 14:54:08 CET 2011
Hello,
On Mar 12, 2011, at 8:32 AM, Maas James Dr (MED) wrote:
> 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?
>
The first question is relatively easy. Try...
first <- c("one","two","three")
second <- sapply(first, function(x) { vector(mode = "list") })
I am unable to help you with your second question.
Cheers,
Ben
> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ben Tupper
Bigelow Laboratory for Ocean Sciences
180 McKown Point Rd. P.O. Box 475
West Boothbay Harbor, Maine 04575-0475
http://www.bigelow.org/
More information about the R-help
mailing list