[Rd] replicating lists

David James David James <dj@research.bell-labs.com>
Wed, 11 Apr 2001 10:00:46 -0400 (EDT)


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!

David A. James
Statistics Research, Room 2C-253            Phone:  (908) 582-3082       
Bell Labs, Lucent Technologies              Fax:    (908) 582-3340
Murray Hill, NJ 09794-0636
------------------------------------------------------------------------

> X-Authentication-Warning: toucan.stats: ripley owned process doing -bs
> Date: Wed, 11 Apr 2001 09:25:32 +0100 (BST)
> From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
> X-X-Sender: <ripley@toucan.stats>
> To: Jonathan Rougier <J.C.Rougier@durham.ac.uk>
> cc: <r-devel@stat.math.ethz.ch>
> Subject: Re: [Rd] replicating lists
> MIME-Version: 1.0
> 
> On Wed, 11 Apr 2001, Jonathan Rougier wrote:
> 
> > Hi Everyone,
> >
> > At the moment it is not possible to replicate complex lists, but only
> > simple ones:
> >
> > > rep(list(fred = 1:10), 10) # works fine
> > > rep(list(fred = 1:10, happy = "squash"), 10)
> > Error in rep(list(fred = 1:10, happy = "squash"), 10) :
> >         Unimplemented feature in rep
> 
> It is implemented in S3 and S4.
> 
> > There is nothing in ?rep that suggests that the latter should not work,
> > and I think it would be a desirable feature if it did.  For example, I
> > want to create an array of lists, and it would be nice for me to set
> > default values in the array function, rather than having to loop through
> > the components and setting them individually.
> >
> > I've had a quick look in do_rep in seq.c and to my untrained eye it looks
> > as though the LISTSXP case of the main switch might need to be replaced by
> > a VECSXP, but I am not sure about other implications.
> 
> I suggest filing this as a bug report.
> 
> -- 
> 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
> 
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


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