[19394] in s-news-athena
[S] Addendum to Summary of
daemon@ATHENA.MIT.EDU (Humbolt, Allen)
Mon Oct 4 14:53:59 1999
Message-Id: <8FE5933BB8DBD111803F00805F9F74BD025B851D@ictmail10.kochind.com>
From: "Humbolt, Allen" <HumboltA@kochind.com>
To: "'s-news@wubios.wustl.edu'" <s-news@wubios.wustl.edu>
Date: Mon, 4 Oct 1999 13:46:51 -0500
Mime-Version: 1.0
Content-Type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: 7bit
Tim Hesterberg followed up to help me understand an even more efficient
solution that he had previously presented to me.
Given my desire to repeat dataframe "Dat" 27 times:
> attr(Dat, "dup.row.names") <- T
> BigDat <- Dat[rep(1:nrow(Dat), 27) , ]
The addition of the attr statement reduced the time required on Splus 2000
from 0.47 seconds to 0.23 seconds. As pointed out by Tim, there's no
efficiency improvement using Splus Version 4.5. I'll add that you'll see
the same thing on Unix Version 3.4 compared to Unix Version 5.0 of Splus.
There's no efficiency improvement via 3.4; but there is significant
improvement via 5.0.
Also, in my SOLUTIONS section I incorrectly identified Tim with the first
solution I presented. He presented the solution above (along with three
others) and added the hint above about using attr.
I also found an irrelevant line my copying of Peter Perkins' solution. I
should have simply stated:
> BigDat <- data.frame(1:(27*nrow(Dat)), Dat)[, -1]
instead of including the extraneous line before it. Since I had mentioned
that this solution succeeds in Splus 2000 while it fails in Splus 4.5, I
wanted to correct this detail for anyone interested in pursuing why Splus
2000 performs differently than Splus 4.5 using Peter's syntax.
Finally, in an e-mail I just received, Jeff Longmate points out that
> Dat[rep(1:ncol(Dat), times=27) , ]
differs from
> Dat[rep(1:ncol(Dat), each=27) , ]
in terms of the sort of the data.
Allen Humbolt
Koch Industries, Inc.
humbolta@kochind.com
> -----Original Message-----
> From: Humbolt, Allen [SMTP:HumboltA@kochind.com]
> Sent: Monday, October 04, 1999 9:55 AM
> To: 's-news@wubios.wustl.edu'
> Subject: [S] Summary of "Reapeating a Data Frame (rows of) 27 Times"
>
>
> Thanks to all who replied. My original question was how to repeat the
> rows
> of data frame "Dat" 27 times, with the suggestion that something like
> rbind(rep(Dat, 27)) ought to work.
>
> The most efficient and intuitively pleasing (to me) answer came from Sam
> Buttrey, Bill Dunlap, Tim Hesterberg, and Joseph Verducci who suggested
> the
> result below. As an reply to some recent s-news responses attributing the
> first solution to Tim, I'll mention that Sam was actually the first to
> send
> me a personal reply with this nice and very simple and efficient solution.
> > BigDat <- Dat[rep (1:nrow(Dat), 27),]
> Charles Berry also sent basically the same idea, which Bill Venables
> expanded upon.
>
> As always, I learned useful concepts from several of the answers, so I
> summarize them below along with the time required to implement them on my
> PC
> for one of my data sets. Thanks again to all.
>
> Allen Humbolt
> Koch Industries, Inc.
> humbolta@kochind.com
>
> SOLUTIONS
> 1. Bill Venables, Nick Locantore, Tim Hesterberg 67.70 sec.
> > BigDat <- NULL
> > for(i in 1:27) BigDat <- rbind(BigDat, Dat)
> 2. Bill Venables 15.93 sec.
> > BigDat <- do.call("rbind", lapply(1:27, function(x) Dat))
> 3. Sam Buttrey, Bill Dunlap, Joseph Verducci 0.45 sec.
> > BigDat <- Dat[rep (1:nrow(Dat), 27),]
> 4. Peter Perkins didn't work
> > BigDat <- Dat
> > BigDat <- data.frame(1:(27*nrow(Dat)),Dat)[,-1]
> However, Peter's solution was efficient and took 1.03 minutes for me via
> Splus 2000.
> I didn't check the details of what I did carefully; but the interesting
> question may be why this did not work on Splus 4.5, but did on 2000. My
> project
> was on Splus 4.5 so I didn't bother to try all these examples on it. I
> tried it
> on 2000 only because I was curious why I couldn't get it to work.
> 5. Erin Hodgess Wouldn't finish; but did finish for smaller
> problem.
> > BigDat <- data.frame(t(rep(data.frame(t(Dat)),5)))
> 6. Chuck Taylor 11.47 sec.
> > doit <- paste("rbind(", paste(rep("Dat", 27), collapse=","), ")")
> > eval(parse(text=doit))
> 7. Charles Berry 0.44 sec
> > BigDat <- data.frame(Dat)[rep(1:318, 27)] # Dat is 318 x 27
> 8. Bill Venables, who attributed to Charles Berrry 0.46 sec
> > rep.matrix <-
> + function(matrix, ...) matrix[rep(seq(1:nrow(matrix)), ...), ]
> > BigDat <- rep.matrix(Dat, times = 27)
>
>
> -----------------------------------------------------------------------
> 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