Hello,
And there's also
#
# library(caTools)
# Author(s)
# Jarek Tuszynski <jaroslaw.w.tuszynski at 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,
Rui Barradas
?s 11:20 de 09/01/20, Helmut Sch?tz escreveu:> Dear Hans,
>
> r-help-request at r-project.org wrote on 2020-01-09 12:00:
>> Date: Wed, 8 Jan 2020 12:09:55 +0100
>> From: Hans W Borchers <hwborchers at gmail.com>
>> To: R help project <r-help at 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
>