Another way that I like is reshape::melt.list() because it keeps track
of the name of the original data.frames,
l = replicate(1e4, data.frame(x=rnorm(100),y=rnorm(100)), simplify=FALSE)
system.time(a - rbind.fill(l))
# user system elapsed
# 2.482 0.111 2.597
system.time(b - melt(l,id=1:2))
I've been doing some consulting with students who seem to come to R
from SAS. They are usually pre-occupied with do loops and it is tough
to persuade them to trust R lists rather than keeping 100s of named
matrices floating around.
Often it happens that there is a list with lots of matrices or
On 09/04/2010 01:37 PM, Paul Johnson wrote:
I've been doing some consulting with students who seem to come to R
from SAS. They are usually pre-occupied with do loops and it is tough
to persuade them to trust R lists rather than keeping 100s of named
matrices floating around.
Often it happens
To echo what Erik said, the second argument of do.call(), arg, takes a
list of arguments that it passes to the specified function. Since
rbind() can bind any number of data frames, each dataframe in mylist
is rbind()ed at once.
These two calls should take about the same time (except for time
Paul;
There is another group of functions that are similar to do.call in
their action of serial applications of a function to a list or vector.
They are somewhat more tolerant in that dyadic operators can be used
as the function argument, whereas do.call is really just expanding the
On Sat, Sep 4, 2010 at 2:37 PM, Paul Johnson pauljoh...@gmail.com wrote:
I've been doing some consulting with students who seem to come to R
from SAS. They are usually pre-occupied with do loops and it is tough
to persuade them to trust R lists rather than keeping 100s of named
matrices
Hi:
Here's my test:
l - vector('list', 1000)
for(i in seq_along(l)) l[[i]] - data.frame(x=rnorm(100),y=rnorm(100))
system.time(u1 - do.call(rbind, l))
user system elapsed
0.490.060.60
resultDF - data.frame()
system.time(for (i in 1:1000) resultDF - rbind(resultDF, l[[i]]))
user
One common way around this is to pre-allocate memory and then to
populate the object using a loop, but a somewhat easier solution here
turns out to be ldply() in the plyr package. The following is the same
idea as do.call(rbind, l), only faster:
system.time(u3 - ldply(l, rbind))
user
8 matches
Mail list logo