Re: [R] R object as a function

From: Thomas Steiner <finbref.2006_at_gmail.com>
Date: Tue, 22 Jan 2008 12:51:14 +0100

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...



R-help_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jan 2008 - 11:55:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jan 2008 - 12:30:08 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive