s-news
[Top] [All Lists]

Re: How to cbind a list to data.frame while avoid using for loop

To: "Sundar Dorai-Raj" <sundar.dorai-raj@pdf.com>
Subject: Re: How to cbind a list to data.frame while avoid using for loop
From: "Brian Wu" <bwu@guzman.com>
Date: Thu, 16 Feb 2006 14:00:50 -0500
Cc: <s-news@lists.biostat.wustl.edu>
Thread-index: AcYzKwzc8YjyiXzHQACbai0hL6UXcwAADg7w
Thread-topic: [S] How to cbind a list to data.frame while avoid using for loop
Cool. Thanks a lot!

-----Original Message-----
From: Sundar Dorai-Raj [mailto:sundar.dorai-raj@pdf.com]
Sent: Thursday, February 16, 2006 2:01 PM
To: Brian Wu
Cc: s-news@lists.biostat.wustl.edu
Subject: Re: [S] How to cbind a list to data.frame while avoid using for
loop


do.call("cbind", temp)

Brian Wu wrote:
> I have a list temp.
> 
> 
>>temp
> 
> [[1]]
>       MSFT
> 1999 37156
> 2000 52150
> 2001 59257
> 2002 67646
> 2003 79571
> 2004 92389
> 
> [[2]]
>         IBM
> 1999  87495
> 2000  88349
> 2001  88313
> 2002  96484
> 2003 104457
> 2004 109183
> 
> [[3]]
>          GOOG
> 1999       NA
> 2000       NA
> 2001       NA
> 2002  286.892
> 2003  871.458
> 2004 3313.351
> 
> Any idea, how to combine the data.frame components into a data.frame avoid 
> using for loop?
> 
> I wanna the result like this:
> 
>>cbind(temp[[1]],temp[[2]],temp[[3]])
> 
>       MSFT    IBM     GOOG
> 1999 37156  87495       NA
> 2000 52150  88349       NA
> 2001 59257  88313       NA
> 2002 67646  96484  286.892
> 2003 79571 104457  871.458
> 2004 92389 109183 3313.351
> 
> the length of the list is variable.
> 
> Any suggestion will be greatly appreciated!
> 
> Brian
> 
> 
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>