Skip to contents

Find the area under a curve of sample points with the trapezoidal rule.

Usage

trapez(x, y)

Arguments

x, y

Numeric vectors giving the coordinates of the sample points.

Value

The scalar numeric integral value.

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