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
On 10/13/2009 03:48 PM, Magnus Torfason wrote:> l = list(list()) > for ( i in sequence(length-1) ) > { > l = list(unlist(l,recursive=FALSE), list()) > }About this : > rep( list(list()), 3 ) [[1]] list() [[2]] list() [[3]] list() Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/BcPw : celebrating R commit #50000 |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc `- http://tr.im/yw8E : New R package : sos
Live and learn ... Thank you! On 10/13/2009 9:57 AM, Romain Francois wrote:> On 10/13/2009 03:48 PM, Magnus Torfason wrote: >> l = list(list()) >> for ( i in sequence(length-1) ) >> { >> l = list(unlist(l,recursive=FALSE), list()) >> } > > About this : > > > rep( list(list()), 3 ) > [[1]] > list() > > [[2]] > list() > > [[3]] > list() > > Romain >
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
On 10/13/2009 10:06 AM, Henrique Dallazuanna wrote:> Try this: > > replicate(3, list())Thanks! I now have three ways to achieve my goal: 1: rep(list(list()), 3) 2: replicate(3, list()) 3: Due to the way R recycles arguments, I found that it is enough to have construct a list(list()), and then perform an assignment using an argument of the length I want (using mapply()). The empty list is then recycled enough times to hold the corresponding values. Best, Magnus