[Rd] bad variable names when printing a data frame containing a matrix (PR#10730)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Feb 9 09:46:55 CET 2008


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



More information about the R-devel mailing list