[R] for() to lapply()

Hadley Wickham h.wickham at auckland.ac.nz
Fri May 21 03:17:29 CEST 2004


> I have the following problem:
> I have a list of data.frames (12 variables and 60000 rows, each)
> 
> I have to merge from an specific point of the list to the
> end of the list, I am doing so with a for() loop but it is
> too inefficient and it exhausts memory.

How about:

a <- list(
	data.frame(a=1),
	data.frame(a=2),
	data.frame(a=3),
	data.frame(a=4)
)
do.call("rbind", a)
do.call("rbind", a[3:4])

(assuming that the data frames have the same variables)

Hadley




More information about the R-help mailing list