Skip to content

problems creating data frames

4 messages · Will Holcomb, jim holtman, Gabor Grothendieck +1 more

#
This should do what you want for the data.frame:
+                          Atenolol = c(4, 8, 10, 3, 6, 5, 6, 3, 7, 5, 4, 6),
+                          Placebo = c(0, 7, 0, 7, 0, 7))
Behavior_Therapy Atenolol Placebo
1                 6        4       0
2                 7        8       7
3                 6       10       0
4                 5        3       7
5                 5        6       0
6                 5        5       7
7                 7        6      NA
8                 8        3      NA
9                 9        7      NA
10                6        5      NA
11                6        4      NA
12                7        6      NA

For the column names, try   check.names=FALSE.
On Fri, Mar 14, 2008 at 4:01 PM, Will Holcomb <wholcomb at gmail.com> wrote:

  
    
#
This was just discussed this week:

https://stat.ethz.ch/pipermail/r-help/2008-March/157082.html
On Fri, Mar 14, 2008 at 5:01 PM, Will Holcomb <wholcomb at gmail.com> wrote:
#
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