[Rd] replicating lists

Prof Brian Ripley ripley@stats.ox.ac.uk
Wed, 11 Apr 2001 17:33:09 +0100 (BST)


The most obvious fix is internal, and that should be done fairly soon.


On Wed, 11 Apr 2001, David James wrote:

> hi,
>
> 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.
>
> David
>
> > Date: Wed, 11 Apr 2001 15:28:02 +0100 (BST)
> > From: Jonathan Rougier <J.C.Rougier@durham.ac.uk>
> > X-Sender: dma0jcr@laplace
> > To: David James <dj@research.bell-labs.com>
> > cc: r-devel@stat.math.ethz.ch
> > Subject: Re: [Rd] replicating lists
> > MIME-Version: 1.0
> >
> > 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._