[R] who to rbind of a list of data.frames
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Aug 12 10:38:50 CEST 2003
> do.call("rbind", LIST)
does exactly
> DF <- rbind(LIST$X1, LIST$X2, LIST$X3, ..., LIST$XN)
See the help on do.call.
Not that rbind.data.frame is `very fast'. If your data frames are
all of exactly the same type (no coercions needed, factors with the same
set of levels, ...) it may be faster to create a new data frame of the
correct size and insert the data frames by indexing.
On Tue, 12 Aug 2003 lutz.thieme at amd.com wrote:
> could anybody give me a hint, who I can use rbind on a list of
> data.frames, please?
>
> I have a list with a large number of data.frames of the same structure, like:
> LIST <- list(X1=data.frame(a=1,b=2), X2=data.frame(a=3,b=4), X3=data.frame(a=5,b=6), ...., XN=data.frame(a=i,b=k))
>
> I would like to bind all data.frames very fast to a single data.frame,
> something like that:
> DF <- rbind(LIST$X1, LIST$X2, LIST$X3, ..., LIST$XN)
>
> But for performance (speed) reasons I won't use a loop.
But rbind.data.frame does use a loop ....
> I also couldn't
> find a solution how I could use lapply. One constraint is, that the
> number of data.frames in the list is not determined and can vary from
> one to more than thousand.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list