timh at insightful.com
2008-Feb-09 00:50 UTC
[Rd] bad variable names when printing a data frame containing a matrix (PR#10730)
library(glmpath) data(heart.data) # heart.data is a list, $y a vector, $x a matrix data <- data.frame(x=I(heart.data$x), y = heart.data$y)> data[1:2,]x.1 x.2 x.3 x.4 x.5 x.6 x.7 x.8 x.9 y 1 160 12 5.73 23.11 1 49 25.3 97.2 52 1 2 144 0.01 4.41 28.61 0 55 28.87 2.06 63 1> dimnames(heart.data$x)[[2]][1] "sbp" "tobacco" "ldl" "adiposity" "famhist" "typea" [7] "obesity" "alcohol" "age" Note that the printed variable names do not use the column names of the matrix. In contrast, in S-PLUS the names are used; the printout begins: x.sbp x.tobacco x.ldl x.adiposity x.famhist x.typea x.obesity x.alcohol --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 6.1 year = 2007 month = 11 day = 26 svn rev = 43537 language = R version.string = R version 2.6.1 (2007-11-26) Windows XP (build 2600) Service Pack 2.0 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:glmpath, package:survival, package:splines, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base
Peter Dalgaard
2008-Feb-09 08:46 UTC
[Rd] bad variable names when printing a data frame containing a matrix (PR#10730)
timh at insightful.com wrote:> library(glmpath) > data(heart.data) > # heart.data is a list, $y a vector, $x a matrix > data <- data.frame(x=I(heart.data$x), y = heart.data$y) > >> data[1:2,] >> > x.1 x.2 x.3 x.4 x.5 x.6 x.7 x.8 x.9 y > 1 160 12 5.73 23.11 1 49 25.3 97.2 52 1 > 2 144 0.01 4.41 28.61 0 55 28.87 2.06 63 1 > >> dimnames(heart.data$x)[[2]] >> > [1] "sbp" "tobacco" "ldl" "adiposity" "famhist" "typea" > [7] "obesity" "alcohol" "age" > > Note that the printed variable names do not use the column names > of the matrix. > > In contrast, in S-PLUS the names are used; the printout begins: > x.sbp x.tobacco x.ldl x.adiposity x.famhist x.typea x.obesity x.alcohol >The reason seems to be that format.AsIs is losing dimnames. That could be easily fixed -- unless I'm overlooking something? -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907