How do I define a list/vector of functions in R? -
I have a function that takes another function as an input variable, like
wrapperfunction & lt; - Function (x, basefunction) {y & lt; - cor (x) basefunction (y)}
Now I want to input various basefonts in this drawing function, output it, but how do I define a list of functions so that Instead of plugging in the hands by each function, I can automate the process for the loop:
for (in i 1: n) {output [i] & lt; - Rapperfunction (X, FunctionList [i])}
I have tried to define
Functionalist & lt; - list () functionalist [1] = function1, etc ....
, which does not work.
Not defined
Functionalist & lt; - c ("Function1", "Function2", ...)
If you want a list of functions, you can do something like this:
myFuns & lt; - List (mean, SD)
and then you can lapply
from this list, or use for
loop As if you wanted to if you use the loop for loop
, make sure that you use the [[
syntax, because it ensures that you Retrieving function and not a list of length:
for (i in 1: n) {output [i] & lt; - wrapperfunction (x, muffins [[i]])}
or
missing (myFuns, wrapperfunction, x = X)
Comments
Post a Comment