Apply a Function of Multiple Arguments

Description

mlapply returns a list of the same length as each of the lists in lol. Each element of the resulting list is the result of applying FUN to all the first elements of the lists in lol, all the second elements of the lists in lol ...
It is the multivariate version of lapply

Usage

1
mlapply(lol,FUN,...)

Arguments

lol

a list of lists, the elements of each list will be used as arguments to calls to FUN

FUN

the function to be applied. In the case of functions like +, %*%, etc., the function name must be backquoted or quoted.

...

Any additional arguments passed to each call to FUN

Value

FUN is a function with the number of arguments being equal to the number of lists contained in lol.
mlapply makes a function call to FUN for all the first elements of all the lists in lol, then a function call to all the second elements of all the lists in lol, and retunrs all the results as a list.
If the first list in lol has named elements, the names will also be used for the elements of the resulting list.

See Also

link{lapply}

Examples

1
2
3
4
mlapply(list(list(1,2,3),list(4,5,6)),function(x,y)x^2+y^2)
mlapply(list(list(a=1,b=2,c=3),list(4,5,6)),function(x,y)x^2+y^2)
mlapply(list(list(a=1,b=2,c=3),list(4,5,6)),function(x,y,e)x^e+y^e,3)
mlapply(list(list(1,2,3),list(4,5,6)),function(x,y,const=0)x^2+y^2+const)