I have a function that accepts a function as an argument. However within my function I need to create a variable depending on which function I passed into it. How can this be achieved?
The following code illustrates the idea (it doesn't work because FUN
cannot be compared against mean
).
myfunc <- function(x,FUN){
if(FUN==mean){y <- 1;}else{y <- 2;}
return(FUN(x+y));
}
Thanks!