[19381] 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 (Joseph S. Verducci)
Sat Oct 2 11:33:34 1999

Date: Sat, 2 Oct 1999 11:24:28 -0400 (EDT)
From: "Joseph S. Verducci" <jsv@stat.ohio-state.edu>
To: Bill Venables <William.Venables@cmis.CSIRO.AU>
Cc: "Humbolt, Allen" <HumboltA@kochind.com>, s-news@wubios.wustl.edu
In-Reply-To: <199910020008.KAA19236@snowy.nsw.cmis.CSIRO.AU>
Message-Id: <Pine.SOL.4.10.9910021122030.3432-100000@jove.mps.ohio-state.edu>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


How about a variant of this problem, where we want
 to repeat the i th row of Dat nreps[i] times?

_____________________________________________

On Sat, 2 Oct 1999, Bill Venables wrote:

> 
> 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
> 

-----------------------------------------------------------------------
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