From J.C.Rougier@durham.ac.uk  Wed Apr 11 15:28:02 2001
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Wed, 11 Apr 2001 15:28:02 +0100 (BST)
Subject: [Rd] replicating lists
In-Reply-To: <200104111400.KAA21045@jessie.research.bell-labs.com>
Message-ID: <Pine.GSO.4.20.0104111524560.13680-100000@laplace>

On Wed, 11 Apr 2001, David James wrote:

> A workaround is to use rep() inside "[":
> 
> > a <- list(a=1, b=2, c=3)
> > a[rep(1:3, 1:3)]
> $a
> [1] 1
> 
> $b
> [1] 2
> 
> $b
> [1] 2
> 
> $c
> [1] 3
> 
> $c
> [1] 3
> 
> $c
> [1] 3
> 
> Note, however, that names are no longer unique!

This work-around is cunning but needs a bit of care, as to get the
replication of the whole of fred you need to wrap the list itself:

> fred <- list(happy = 1:10, fred = "squash")
> list(fred)[rep(1, 10)] # list with 10 copies of fred

Cheers, Jonathn.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] replicating lists
Jonathan Rougier