[R] using functions with multiple arguments in the "apply" family

casalott k.lotterhos at gmail.com
Thu Aug 12 02:50:23 CEST 2010



I can actually answer this!!  I was trying to figure out how to use sapply
for a function I wrote with multiple arguments.
Suppose the function is called
FUN(a,b), where "a" is a number and "b" is a number
You can use mapply(FUN, a = VECTOR, b = VECTOR) where each vector is your
input arguments.  It will output a vector or a matrix (depending on the
output of your function).

This will also work:
mapply(FUN, a = VECTOR, b = NUMBER) and will apply your function with each
element of "a" but the same argument for "b" each time.

Let me know if it works!

-- 
View this message in context: http://r.789695.n4.nabble.com/using-functions-with-multiple-arguments-in-the-apply-family-tp1312027p2322067.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list