[R] multidimensional list
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed May 23 12:31:05 CEST 2001
On Wed, 23 May 2001, Jonathan Rougier wrote:
> Hi Sven,
>
> On Wed, 23 May 2001, Sven Garbade wrote:
>
> > is it possible to create a multidemensional list? Haven't found anything
> > in the list() help page.
>
> Yes it is, although there are some slight bugs to be aware of. If you
> have
>
> > fred <- as.list(1:12)
>
> then you can make fred into a dimensioned list simply by doing
>
> > dim(fred) <- c(3, 4)
>
> and then you can do things like
>
> > fred[[1, 2]] <- list(happy = 1:10, sad = "armadillo")
>
> There are a couple of things that don't work very well. At version 1.2.1
> (a bit out of date but my latest version) you will get a segmentation
(Um. Try upgrading to R-devel.)
> fault if you do the incorrect
>
> > fred[[1, ]]
>
> but this has been corrected on later versions. It is still a bit
> difficult to make a dimensioned list by doing
>
> > array(list(happy = 1:10, sad = "armadillo"), c(3, 4))
>
> but that is because rep does not (yet) handle lists *except* simple lists
> like
>
> > array(list(happy = 1:10), c(3, 4))
>
> I believe that this is being addressed. But with ingenuity you can get
Has been addressed: it works in the R-devel version.
> around this, for example I have used a construction like
>
> > fred <- array(list(list(happy = 1:10, sad = "armadillo")), c(3, 4))
--
Brian D. Ripley, ripley at 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-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list