[Rd] several bugs (PR#918) lists and matrices
Jonathan Rougier
J.C.Rougier@durham.ac.uk
Tue, 24 Apr 2001 09:49:16 +0100 (BST)
Hi Robert,
On Mon, 23 Apr 2001, Robert Gentleman wrote:
> I am uncertain as to why you want to put dimensions on a list? It
> doesn't make it a matrix. That said we can duplicate the behaviour
> but I'm not sure that it is worth introducing the confusion that
> ought to follow.
Just to second Rich's reply: I love putting dimensions on a list! I often
have rectangular data-structures of heterogeneous objects, and find it
much easier to operate with one large structure than several matching
small ones.
For example, at the moment I have a dynamic programming problem in which I
need to retain the expected payoff and the action, plus possibly some
other stuff as well, on a 2-grid. I find it natural to write
dprog <- array(list(), c(20, 30))
# solving the dynamic programme
for (i in 20:1) for (j in 1:30) {
# stuff here
dprog[[i, j]] <- list(Ep = -1.0, action = "run for the hills")
# and then, if I need to ...
dprog[[i, j]]$andAnotherThing <- "don't look back"
}
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._