timhesterberg at gmail.com
2008-Aug-27 17:05 UTC
[Rd] format.data.frame handles names in nested data frames badly (PR#12624)
> d <- data.frame(x=1:3, y=2:4) > d[["r"]] <- d[1]/d[2] > dx y x 1 1 2 0.5000000 2 2 3 0.6666667 3 3 4 0.7500000 It appears that the name "x" was given instead of "r". That is not correct:> names(d)[1] "x" "y" "r"> showStructure(d) # from package splus2Rlist[3,3] S3 class: data.frame &row.names numeric[ length 3] class: integer $x numeric[ length 3] class: integer $y numeric[ length 3] class: integer $r list[3,1] S3 class: data.frame &row.names numeric[ length 3] class: integer $x numeric[ length 3] class: numeric print.data.frame calls format.data.frame, which loses the name "r" and substitutes the name "x". I suggest that format.data.frame (or print.data.frame) paste together the names, e.g. x y r.x 1 1 2 0.5000000 2 2 3 0.6666667 3 3 4 0.7500000 This generalizes to the case that an included data frame includes two columns. It is also consistent with the behavior for a data frame containing a matrix.> d <- data.frame(x=1:3, y=2:4, A = I(cbind(a=3:5,b=4:6))) > dx y A.a A.b 1 1 2 3 4 2 2 3 4 5 3 3 4 5 6> showStructure(d)list[3,3] S3 class: data.frame &row.names numeric[ length 3] class: integer $x numeric[ length 3] class: integer $y numeric[ length 3] class: integer $A numeric[3,2] S3 class: AsIs attributes: dimnames --please do not edit the information below-- Version: platform = i486-pc-linux-gnu arch = i486 os = linux-gnu system = i486, linux-gnu status major = 2 minor = 7.1 year = 2008 month = 06 day = 23 svn rev = 45970 language = R version.string = R version 2.7.1 (2008-06-23) Locale: LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C Search Path: .GlobalEnv, package:Rfixes, package:Rcode, package:aggregate, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:showStructure, package:splus2R, package:methods, Autoloads, package:base [[alternative HTML version deleted]]