Martin Maechler
1998-Jan-16 18:12 UTC
data.frame(...) not constructing "1:n" row.names [diff. S <--> R]
[I think Doug Bates has already alluded to this, somewhere..] In R, data.frame( ... ) does not construct row.names whereas in S, it does: R:> data.frame(x=1:2,y=3:4)x y [1,] 1 3 [2,] 2 4> row.names(data.frame(x=1:2,y=3:4))NULL S-plus:> data.frame(x=1:2,y=3:4)x y 1 1 3 2 2 4> row.names(data.frame(x=1:2,y=3:4))[1] "1" "2" --------------------------------------------------------------------------- R core: Is there a good reason for this? Well (as a member of R-core, I give my answer): Memory efficiency can be a good reason, actually... together with ``cleanness'' : ``1:n'' are the IMPLICIT DEFAULT row.names We could stay at the current way `internally', but make sure that all functions working on data.frames `d.f' automatically work as if row.names(d.f) *was indeed* == paste(1:nrow(d.f) Some of them maybe even are, (lm, glm, and their methods ??) but not 'print.data.frame' (a <primitive>) nor row.names(.) or dimnames(.) (also <primitive>). (and if dimnames is fixed, rownames(.) [the one without "."] will also work]. It may well be that it is sufficient to upgrade print.data.frame dimnames and row.names (which is trivial to fix). On the other hand, attr(d.f, "row.names") [yet another <primitive> !] would also have to be fixed for `complete' S compatibility which is less "clean". Martin Maechler <maechler@stat.math.ethz.ch> <>< Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1086 http://www.stat.math.ethz.ch/~maechler/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
1998-Jan-16 18:34 UTC
data.frame(...) not constructing "1:n" row.names [diff. S <--> R]
Martin Maechler <maechler@stat.math.ethz.ch> writes:> > [I think Doug Bates has already alluded to this, somewhere..] > > In R, data.frame( ... ) > > does not construct row.names whereas in S, it does:...> R core: Is there a good reason for this?No.> Well (as a member of R-core, I give my answer): > > Memory efficiency can be a good reason, actually... > together with ``cleanness'' : > ``1:n'' are the IMPLICIT DEFAULT row.names > > We could stay at the current way `internally', > but make sure that all functions working on data.frames `d.f' > automatically work as if > > row.names(d.f) *was indeed* == paste(1:nrow(d.f)Ugh. Please, let's avoid implicit stuff. All the special-casing involved all over the place would soon outweigh the saved storage of a character vector. We'll get nothing but trouble from it. Just add the rownames. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._