[R] How to iterate through two objects of class "list" fast?
Thomas Lumley
tlumley at u.washington.edu
Wed Jun 2 16:39:13 CEST 2004
On Wed, 2 Jun 2004, Peter Dalgaard wrote:
> "Wolski" <wolski at molgen.mpg.de> writes:
>
> > list3[[x]] <- myfunc(list1[[x]],list2[[x]])
> >
> > Until now I am runnign this in a for(x in 1:length(list1)) loop. But "for" loops are slow especially if list3 is HUGE.
> >
> > What can I do?
>
> Use mapply(). I wouldn't expect the for loop to be all that slow
> unless you have forgotten to allocate memory for the result list up
> front, though.
>
If you preallocate the memory the for loop is probably faster than
mapply().
-thomas
More information about the R-help
mailing list