blk.diff | R Documentation |
Computes lagged difference within blocks and on selected elements.
blk.diff(x, id, ind = NULL, lag = 1, fill = NA, diff.op = "-", ...)
blk.intereventTime(time, id, ind = NULL, lag = 1, fill = NA, diff.op = difftime.default, ...)
x,time |
A vector in |
id |
A valid |
ind |
A logical vector that designates a subset of |
lag |
An integer specifying the lag. |
fill |
A value to use when no other value is appropriate. |
diff.op |
A function that subtracts one value from another. |
... |
Further arguments passed to |
These functions operate on data sets in block-format
.
Essentially, the standard diff
function is applied
within each block, except that a function diff.op
can be
specified for doing the subtraction. Additionally, a subset on
which to perform the operation can be selected with ind
. For
elements that are not selected the corresponding result is given by
fill
. The first lag
elements of each block are the
result are also assigned the value fill
so that the result is
in block-format
with respect to id
.
For time values, blk.intereventTime
is an alias with a more
descriptive name and a different default diff.op
.
A vector in block-format
with respect to id
containing the differenced values.
Benjamin Rich <mail@benjaminrich.net>
block-format
diff
deltat
require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,] # First 4 subjects
attach(dat)
cbind(dat, INTERDOSE.TIME=blk.intereventTime(time, asID(Subject), ind=!is.na(dose)))
detach(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.