Re: [R] creating list of lists

From: Ben Tupper <btupper_at_bigelow.org>
Date: Sat, 12 Mar 2011 08:54:08 -0500

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/



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. Received on Sat 12 Mar 2011 - 13:58:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Mar 2011 - 14:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive