# [R] R-help Digest, Vol 203, Issue 8

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Fri Jan 10 06:22:13 CET 2020

```Hello,

And there's also

#
# library(caTools)
# Author(s)
# Jarek Tuszynski <jaroslaw.w.tuszynski using saic.com>
#
# Original
trapz <- function(x, y){
idx = 2:length(x)
return(as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1]) ) / 2)
}

# Modified by me, input is x, f(x)
trapzf <- function(x, FUN) trapz(x, FUN(x))
# Call like 'integrate'
trapzf2 <- function(f, lower, upper, subdivisions = 100){
trapzf(seq(lower, upper, length.out = subdivisions), match.fun(f))
}

So I guess it's not missing, just missing in base R, like the OP said.

Hope this helps,

Às 11:20 de 09/01/20, Helmut Schütz escreveu:
> Dear Hans,
>
> r-help-request using r-project.org wrote on 2020-01-09 12:00:
>> Date: Wed, 8 Jan 2020 12:09:55 +0100
>> From: Hans W Borchers <hwborchers using gmail.com>
>> To: R help project <r-help using r-project.org>
>> Subject: [R] Which external functions are called in a package?
>>     [Solved]
>>
>> NB: `trapz`, ie.
>> the trapezoidal integration formula, seems to be the numerical
>> function to be missed the most in R base.
>
> In R base indeed. However available in Frank Harrels Hmisc as the
> function trap.rule(x, y) for sorted values.
> In plain R: function(x, y) sum(diff(x) * (y[-1] + y[-length(y)]))/2
>
> Helmut
>

```