Find the area under a curve of sample points with the trapezoidal rule.
See also
integrate()
for general-purpose numeric integration.
Examples
trapez(c(0, 1, 2), c(1, 2, 0))
#> [1] 2.5
# Calculate AUClast for each subject in the Indometh dataset
Indometh |> by(~ Subject, with, trapez(c(0, time), c(0, conc)))
#> Subject: 1
#> [1] 1.74125
#> ------------------------------------------------------------
#> Subject: 4
#> [1] 2.4775
#> ------------------------------------------------------------
#> Subject: 2
#> [1] 2.9325
#> ------------------------------------------------------------
#> Subject: 5
#> [1] 1.95375
#> ------------------------------------------------------------
#> Subject: 6
#> [1] 2.8725
#> ------------------------------------------------------------
#> Subject: 3
#> [1] 2.93375