| blk.time.above.threshold | R Documentation |
Compute the time above a threshold by linear interpolation within
each block of a block-format data set.
blk.time.above.threshold(x, y, threshold, id, id2 = id, ind = NULL, fill = NA, diff.op.x = "-", diff.op.y = "-", ...)
x,y |
A vector in |
threshold |
A numeric vector of length one specifying the threshold. |
id |
A valid |
id2 |
A valid |
ind |
A logical vector that designates a subset of points. By default all points are included. |
fill |
A value to use when no other value is appropriate. |
diff.op.x |
A function that computes differences in |
diff.op.y |
A function that computes differences in |
... |
Further arguments passed to |
This function operates on data sets in block-format.
Within each block,
the points on a graph are determined by x and y. A
subset of points to include can be specified with ind.
Then, within each block, the time above threshold is computed
by linear interpolation.
The parameter id2 determines the return value.
If id2 is NULL, the returned vector contains one
element for each level of id, with fill used for
blocks of size zero.
If id2 is NULL,
a vector containing one value for
each level of id. Otherwise,
a vectors in block-format with respect to id2.
Benjamin Rich <mail@benjaminrich.net>
block-format
threshold <- 5
x0 <- 1:20
y0 <- 0.1 + runif(20, 0, 0.9)
y0[6] <- y0[5]
y0[14] <- y0[11]
y0[c(16)] <- 0
y0[c(2, 3, 4, 7, 8, 9, 15, 16, 18)] <- 0
y0[c(1, 10, 11, 12, 13, 14, 15, 19, 20)] <- -y0[c(1, 10, 11, 12, 13, 14, 15, 19, 20)]
y0[c(1, 10, 19)] <- -y0[c(5, 6, 17)]
y0 <-(1 + y0)*threshold
x <- x0[c(1, 5, 6, 10, 11, 14, 16, 17, 19, 20)]
y <- y0[c(1, 5, 6, 10, 11, 14, 16, 17, 19, 20)]
plot(x0, y0, type="n", ylim=c(0, 2*threshold)); abline(h=threshold, col="red", lwd=3)
points(x0, rep(threshold, length(x0)), col="red", pch=19, cex=1)
lines(x, y, type="b", col="blue", lwd=2)
t <- blk.time.above.threshold(x, y, threshold, id=asID(rep(1, length(x2))), id2=NULL)
stopifnot(t == 7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.