[R] using "integrate" in a function definition

theo borm theo_rstt at borm.org
Fri Feb 23 22:58:02 CET 2007


Hi,

Many thanks for the explanation.

Alberto Monteiro wrote:

>
>PS: fff <- function(x) 1 
>integrate(fff, 0, 1)  # error. why?
>

Guess: because integrate itself expects a "vectorized function" ?

 > fff(1:5)
[1] 1
 > ggg<-function(x) { sapply(x, function(x)1) }
 > ggg(1:5)
[1] 1 1 1 1 1
 > integrate(ggg,0,1)
1 with absolute error < 1.1e-14
 > hhh<-function(x) 1+0*x
 > integrate(hhh, 0, 1)
1 with absolute error < 1.1e-14

I sense a certain lack of intuitiveness here :-/


regards, Theo



More information about the R-help mailing list