Reputation: 444
I want to code a function that takes in a number and returns a function with that number as a parameter. I want to later find the roots of this function it outputs.
fooToOptimze <- function(PD) {
f <- function(C, k) { 0.089 * exp(1.6234 * PD) - C * exp(k * PD)}
return(f)
}
However, this way, I get:
fooToOptimize(.5)
OUTPUT
function(C, k) { 0.089 * exp(1.6234 * PD) - C * exp(k * PD)}
How should I approach this?
Upvotes: 0
Views: 73
Reputation: 4233
You don't have to use purrr
for this. Your function seems to look OK. Again, suppose you want to create a function that takes a
and b
as parameters and returns a function for evaluating ax+b
. Here is what you do:
lin <- function(a,b){
function(x) a*x + b
}
Then lin(1,1)(1)
will give you 1*1 + 1 = 2
. lin(1,0)(x)
will just give you the input value back for any x
.
Upvotes: 1