Hello,

And there's also


#
# library(caTools)
# Author(s)
# Jarek Tuszynski <jaroslaw.w.tuszyn...@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-requ...@r-project.org wrote on 2020-01-09 12:00:
Date: Wed, 8 Jan 2020 12:09:55 +0100
From: Hans W Borchers <hwborch...@gmail.com>
To: R help project <r-help@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


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to