Skip to content
Prev 139565 / 398506 Next

problems creating data frames

Another approach might be to start with a list, pad
the vectors and then convert to a data.frame.  Here is
something that Henrique Dallazuanna and Phil Spector
suggested to me a couple of days ago as a way of
solving something of a similar problem. 

It seems to have the advantage that it will handle
characters and factors as well.

worrylist = list(Behavior_Therapy = c(6, 7, 6, 5, 5,
5, 7, 8, 9, 6, 6, 7),
                          Atenolol = c(4, 8, 10, 3, 6,
5, 6, 3, 7, 5, 4, 6),
                          Placebo = c(0, 7, 0, 7, 0,
7))
                          
mlen = max(sapply(worrylist,length))
eqlens = lapply(worrylist,function(x)if(length(x) <
mlen)
                           
c(x,rep(NA,mlen-length(x))) else x)
                            
kitbag <- do.call(data.frame, eqlens) ; kitbag 


As for the names I think you're running into some kind
of naming conventions in the assign statement.  As a
work around why not just call the vectors x,y,a and
then do a names(mydata) <- c( "S+P-", and so on)


--- Gabor Grothendieck <ggrothendieck at gmail.com>
wrote:
https://stat.ethz.ch/pipermail/r-help/2008-March/157082.html