[19378] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Repeating a Data Frame

daemon@ATHENA.MIT.EDU (Bill Venables)
Fri Oct 1 20:16:50 1999

Message-Id: <199910020008.KAA19236@snowy.nsw.cmis.CSIRO.AU>
To: "Humbolt, Allen" <HumboltA@kochind.com>
Cc: s-news@wubios.wustl.edu
In-Reply-To: Your message of "Fri, 01 Oct 1999 17:19:32 EST."
             <8FE5933BB8DBD111803F00805F9F74BD025B851A@ictmail10.kochind.com> 
Date: Sat, 02 Oct 1999 10:06:11 +1000
From: Bill Venables <William.Venables@cmis.CSIRO.AU>


Hi Allen,

How's tricks?

> I've got a dataframe I'll call "Dat" that I'd like to repeat 27 times.
> I want to do something like
>   BigDat <- rbind(rep(Dat, 27))
> but that doesn't work like I want when Dat is a dataframe.  
> It just creates the same number of rows with my columns repeated 27 times.
> I want BigDat to have the same number of columns with 27 times as many rows.
> 
> Can someone show me how to do this?

I think it needs a loop.  The simplest is certainly

BigDat <- NULL
for(i in 1:27) BigDat <- rbind(BigDat, Dat)

If 27 really is the number and you want to do this sort of thing
all the time you can slick things up just slightly by

BigDat <- Dat
for(i in 1:3) BigDat <- rbind(BigDat, BigDat, BigDat)

[think about it...]

You can hide the loop in various clever ways, such as

BigDat <- do.call("rbind", lapply(1:27, function(x) Dat))

but I'd be very surprised if you gained all that much...

Bill.
-- 
-----------------------------------------------------------------
Bill Venables, Statistician, CMIS Environmetrics Project.

Physical address:                            Postal address:
CSIRO Marine Laboratories,                   PO Box 120,       
233 Middle St, Cleveland, Queensland         Cleveland, Qld, 4163
AUSTRALIA                                    AUSTRALIA

Telephone: +61 7 3826 7251     Email: Bill.Venables@cmis.csiro.au     
      Fax: +61 7 3826 7304
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

home help back first fref pref prev next nref lref last post