[R] R object as a function
Thomas Steiner
finbref.2006 at gmail.com
Tue Jan 22 13:52:29 CET 2008
Thank you very much Duncan for your quick answers.
> You're not passing a function as myfunk1, you're passing mf, which is
> the result of evaluating myfun1, so it's a numeric vector.
Yes, this is exacty my problem.
If I leave it away, the problem will not be resolved (it needs pa or not)
myfun1<-function(x,pa) {
return(pa[1]*x^2+pa[2]*x+pa[3])
}
myfun2<-function(x,param,myfunk1) {
return(param[1]*myfunk1(x)+param[2]*myfunk1(x))
}
test<-function(pars1,pars2,lo,up){
integ=integrate(f=myfun2,lower=lo,upper=up,param=pars2,myfunk1=myfun1)#pa=pars1
return( 2*integ$value )
}
test(pars1=c(1,2,3),pars2=c(-1,1),lo=2,up=7)
Which gives an error:
Once the "argument pa" is missing and if you add the "pa=pars1" in
the comment, it says that the argument pa is redundant.
Thanks for help,
Thomas
More information about the R-help
mailing list