I have a function f(var1, var2) in R. Suppose we set var2 = 1 and now I want to apply the function f() to the list L. Basically I want to get a new list L* with the outputs
[f(L[1],1),f(L[2],1),...,f(L[n],1)]
How do I do this with either apply, mapply or lapply?
Just pass var2 as an extra argument to one of the apply functions.
This passes the same
var2to every call ofmyfxn. If instead you want each call ofmyfxnto get the 1st/2nd/3rd/etc. element of bothmylistandvar2, then you’re inmapply‘s domain.