[R] dim enquiry

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 17 20:36:45 CET 1999


On 17 Feb 1999, Peter Dalgaard BSA wrote:

> Jonathan Rougier <J.C.Rougier at durham.ac.uk> writes:
> 
> > This is a minor question, but is there any difference between the two
> > objects
> > 
> > fred <- structure(1:10, dim = c(2,5))
> > 
> > and
> > 
> > fred <- structure(1:10, .Dim = c(2,5))
> 
> No:
> 
> R> dput(structure(1:10, dim = c(2,5)))
> structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), .Dim = c(2, 5))
> R> dput(structure(1:10, .Dim = c(2,5)))
> structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), .Dim = c(2, 5))
> 
> > Should I be using one rather than the other?  Thanks, Jonathan.
> 
> I think the dim= form is marginally better. .Dim gets internally
> converted to dim anyway. (But don't ask me why dput represents it
> using .Dim...)

May I suggest that it is much safer not to use structure at all?

array(1:10, dim = c(2,5))
matrix(1:10, 2, 5)

are much higher-level, and do not depend on representations. I think
structure should only be used in `new' functions for classes.  This may
seem purist (it is), but when S4 came along (in S-PLUS 5) the purist code
continued to work, and quite a lot of the low-level code needed to be
changed. Perhaps one day matrices and arrays will acquire classes in R,
and then structure(1:10, dim = c(2,5)) will not be a matrix, which is
presumably what you want it to be.


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