[Rd] replicating lists

Prof Brian Ripley ripley@stats.ox.ac.uk
Thu, 12 Apr 2001 09:40:43 +0100 (BST)

```On Thu, 12 Apr 2001, Jonathan Rougier wrote:

> Hi Brian,
>
> After a discussion with David James can you clarify exactly what you think
> the behaviour of "rep" will be?  The three alternatives for rep(fred, 5)
> would appear to be
>
> > fred <- list(happy = 1:10, name = "squash")
> > list(fred)[rep(1, 5)]                          # version 1
> > fred[rep(seq(along=fred), length=5)]           # version 2
> > unlist(list(fred)[rep(1, 5)], recursive=FALSE) # version 3
>
> I was expecting the first, as this makes sense in the context of
>
> > tmp <- array(fred, c(3, 4))
>
> but I can see that the second is also a natural way to think about
> replicating a list.  I also notice that S+ uses version 3.  Personally I
> don't like version 3 as it is going to duplicate names, and it is not
> going to fit with "array".
>
> Confused, Jonathan.

We follow the prototype in cases of doubt, so version 3.  *However*,
S-PLUS does different things by version, so version 6.0 drops the
duplicated names.  I really think only 3 makes sense: a list is a generic
vector, and you do exactly the same thing as for any other sort of vector.
The only issue is the names, and

x <- letters[1:3]
names(x) <- x
rep(x, 5)

drops names in S+6.0, keeps them in S+3.4 and R.  So the S-PLUS versions
are doing consistent things with character vectors and lists.

As for array, again it fits with all other sorts of vectors.   I think you
are misconceiving what a list is: think of it as a vector with
components of different types.  An array list is just an array with
elements of different types.  The problems you had with [[1, ]] stem from
the same problem,

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

```