[R] Apply and its friends

Thomas W Blackwell tblackw at umich.edu
Mon Oct 6 14:13:09 CEST 2003


Crispin  -

This is a familiar problem.  The only way I know of to do it is:

result <- lapply(seq(along=list.a), function(i,a,b) do.it(a[[i]], b[[i]]), list.a, list.b)

Here,  do.it()  is the function which operates on two elements.
I use this construction frequently.

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 6 Oct 2003, Crispin Miller wrote:

> I need to take two lists-of-lists, and apply a function to each
> pair of elements in the lists  to return a single list...
> For example
>
> l1 <- list(1:5,6:10,2:15)
> l2 <- list(1:8,4:12,1:19,4:20)
>
> I could easily do an lapply across each of them, but is there a
> function that does a sort-of pairwise-apply across both together?
>
> Does anybody know of a good document that discusses this kind of
> basic matrix/list/vector manipulation in R?
> Regards,
> crispin




More information about the R-help mailing list