[R] integration of a discrete function

Thomas Lumley tlumley at u.washington.edu
Sun Apr 21 22:54:31 CEST 2002


On Sat, 20 Apr 2002, Giuseppe  Pagnoni wrote:

> Dear R list
>
> I am looking for a function in R that computes the integration of a
> discrete curve, such as a power spectrum, in a specified interval (in my
> case, that would be 'power in a certain frequency band').  I found only
> functions, such as 'integrate', that perform adaptive quadrature on
> analytic functions, and not on a curve specified as a set of (x,y) pairs.
> I have the impression that I am not looking in the right place....  or I
> should code the algorithm myself?

You should probably code it yourself.

When you have a genuinely discrete function the integral will usually be
exactly
    sum(w*x)
where w is a vector of weights that will depend on x in a problem-specific
way (that being why you want to do it yourself). You probably don't want
the sort of approximations that adaptive quadrature would do.

OTOH, if you have data (x,y) and want to integrate a smooth or
interpolated curve you could use approxfun() or splinefun() to create that
smooth curve and integrate it. [Someone will probably point out that you
don't actually need to integrate() it, since linear and spline functions
have closed-form integrals]

	-thomas

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list