trapz: Trapezoid integral calculation

Description Usage Arguments Details Value Examples

View source: R/FCMm.R

Description

Trapezoid integral calculation

Usage

1
2
3
trapz(wv, x)

trapz2(x)

Arguments

wv

wavelength

x

data.frame that need to be trapzed with ncol equal to length of wv. Note that the colnames of x should be converted to numbers for trapz. Do not name them as "Rrs560", "560nm" or so. Just set as "560".

Details

In 2020-11-02, I created an improved version of trapz, say trapz. So better to use trapz as it calculates much faster than before.

Value

A vector presenting the area result.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(FCMm)
library(magrittr)
library(stringr)
data("Nechad2015")
w <- Nechad2015 %>% names %>%
    str_extract(.,pattern="\\d") %>%
    is.na %>% {!.}
wv <- w %>% names(Nechad2015)[.] %>%
    gsub('X','',.) %>% as.numeric
x <- w %>% Nechad2015[,.]
names(x) <- wv
rm(w)
Area <- trapz(wv, x)
Area2 <- trapz2(x) # the results are indentical to that from trapz

bishun945/FCMm documentation built on Oct. 15, 2021, 6:43 p.m.