Hello everybody, 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. 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. Any help is apreciated, thank you in advance. Kind regards, Lutz Lutz Thieme Product Engineering AMD Saxony Limited Liability Company & Co. KG M/S E22-PE, Wilschdorfer Landstr. 101 D-01109 Dresden, Gemany phone: + 49-351-277 - 4269 fax: + 49-351-277-9-4269
> 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
lutz.thieme at amd.com writes:> Hello everybody, > > 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. 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. > Any help is apreciated, thank you in advance.Bill V.'s favourite trick: do.call("rbind", LIST)> Lutz Thieme > Product Engineering > AMD Saxony Limited Liability Company & Co. KGAnyone tried getting R to run on Opterons in 64 bit mode BTW? Those machines are quickly approaching Xeon prices around here.. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907