# intergral: In chenpanliao/cccR: Color contrast calculator with R

## Usage

 `1` ```intergral(x, y) ```

## Arguments

 `x` `y`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46``` ```##---- Should be DIRECTLY executable !! ---- ##-- ==> Define data, use random, ##-- or do help(data=index) for the standard data sets. ## The function is currently defined as function (x, y) { temp <- na.omit(data.frame(x, y)) x <- temp\$x y <- temp\$y if (length(x) != length(y)) { stop("Length of x and y must be equal.") } if (length(x) < 2 | length(y) < 2) { stop("Length of x and y must larger than 1") } x.index <- order(x) xx <- x[x.index] yy <- y[x.index] n <- length(xx) xx.d <- xx[2] - xx[1] xx.cal <- numeric(n) for (k in 1:length(xx.cal)) { xx.cal[k] <- xx[1] + (k - 1) * xx.d } if (!all(xx == xx.cal)) { is.uniform <- F warning("x is not an arithmetic sequence.") } else { is.uniform <- T } if (is.uniform) { area <- ((xx[n] - xx[1])/2/(n - 1)) * (sum(yy) + sum(yy[2:(n - 1)])) } else { area.part <- numeric(n - 1) for (k in 1:(n - 1)) { area.part[k] <- (yy[k] + yy[k + 1]) * (xx[k + 1] - xx[k])/2 } area <- sum(area.part) } return(area) } ```

chenpanliao/cccR documentation built on May 10, 2019, 1:09 a.m.