From J.C.Rougier@durham.ac.uk  Wed Apr 11 16:14:04 2001
From: J.C.Rougier@durham.ac.uk (Jonathan Rougier)
Date: Wed, 11 Apr 2001 16:14:04 +0100 (BST)
Subject: [Rd] replicating lists
In-Reply-To: <200104111457.KAA05539@jessie.research.bell-labs.com>
Message-ID: <Pine.GSO.4.20.0104111605580.13680-100000@laplace>

On Wed, 11 Apr 2001, David James wrote:

> Yes, I agree that the work-around needs some care, but I'm not sure 
> we need to wrap the list itself -- we're simply using properties of 
> "[" on lists.  If the subscript is rep(1, 10), then we'll get the 
> first element 10 times (which is *not* replicating the list).
> To get the replication we need to index every element in 
> the list as many times as required.

Not sure I follow you here.  I want n copies of an arbitrary list, as a
list, so list(fred)[rep(1, n)] is desired, where fred is the list I want
replicated.  Unfortuntely this does not solve the underlying problem,
which is that I want to do

> tmp <- array(fred, c(3, 4))

which breaks because "rep", invoked by "array", currently fails to handle
complex lists.  However I am happy to report that

> tmp <- array(list(fred)[rep(1, 12)], c(3, 4))

does work as expected:

> tmp[[3, 4]] # fred again!

So that's the work-around in my particular case.

Cheers, Jonathan.

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