[R] R object as a function

Thomas Steiner finbref.2006 at gmail.com
Tue Jan 22 12:51:14 CET 2008


Okay, let me try to better say what I meant:

myfun1<-function(x=5,pa) {
  return(pa[1]*x^2+pa[2]*x+pa[3])
}
myfun2<-function(x=5,param,myfunk1) {
  return(param[1]*myfunk1(x)+param[2]*myfunk1(x))
}
test<-function(pars1,pars2,lo,up){
  mf=myfun1(x=2,pa=8*pars1)
  integ=integrate(f=myfun2,lower=lo,upper=up,param=pars2,myfunk1=mf)
  return( 2*integ$value )
}
test(pars1=c(1,2,3),pars2=c(-1,1),lo=2,up=7)

So the function myfun2 will be integrated and has a function (myfunk1)
itself as an argument.
Why is this not possible?
Thanks,
Thomas

PS: the "x=5" and "pa=8*" has no influence...



More information about the R-help mailing list