[R] Problem with as.data.frame when an extra attribute is present

Frank E Harrell Jr f.harrell at vanderbilt.edu
Fri Nov 10 04:26:06 CET 2006


I have a problem when one of the vectors in a list needs to be 
replicated to have the appropriate length, and an attribute is present.

 > w <- list(a=1, b=2:3)
 > as.data.frame(w)
   a b
1 1 2
2 1 3

 > attr(w$a,'label') <- 'foo'
 > as.data.frame(w)
Error in data.frame(a = 1, b = c(2, 3), check.names = TRUE) :
         arguments imply differing number of rows: 1, 2

I usually use the Hmisc label function to make a variable of class 
'labelled' and define as.data.frame.labelled as as.data.frame.vector, 
but that also fails here.  Any help appreciated.  -Frank

 > sessionInfo()
R version 2.2.1, 2005-12-20, i486-pc-linux-gnu [also fails in 2.4.0]

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "base"

-- 
Frank E Harrell Jr   Professor and Chair           School of Medicine
                      Department of Biostatistics   Vanderbilt University



More information about the R-help mailing list