[R] expression input to a function

Naresh Gurbuxani naresh_gurbuxani at hotmail.com
Wed May 4 13:11:01 CEST 2016


I am trying to write a function, which can be made very general if one of the inputs can be an expression.  How can this be done?


For example, to find root of a function, I would like to say

my.func <- function(x) {x^3 + 2 * (x^2) - 7}

x.left <- 0
x.right <- 2
n.iterations <- 0

find.root <- function(my.func, x.left, x.right) {
 # code here
return(c(x.mid, n.iterations))
}

The above method clearly does not work.  

Thanks,
Naresh


More information about the R-help mailing list