[R] Creating a list of empty lists

Henrique Dallazuanna wwwhsd at gmail.com
Tue Oct 13 16:06:20 CEST 2009


Try this:

replicate(3, list())

On Tue, Oct 13, 2009 at 10:48 AM, Magnus Torfason
<zulutime.net at gmail.com> wrote:
> Well here is one more brain-teaser related to assigning stuff into a list of
> list. What if I need to create a new list of empty lists? I have actually
> got a solution to this problem:
>
>    l = list(list())
>    for ( i in sequence(length-1) )
>    {
>        l = list(unlist(l,recursive=FALSE), list())
>    }
>
> But it is not very neat to do this in a loop. Are there any cuter ways to do
> this?
>
> Best,
> Magnus
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list