blk.diff: Blockwise Lagged Differences

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Computes lagged difference within blocks and on selected elements.

Usage

1
2
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, ...)

Arguments

x,time

A vector in block-format with respect to id.

id

A valid block-format ID.

ind

A logical vector that designates a subset of x. By default all are included.

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 diff.op.

Details

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.

Value

A vector in block-format with respect to id containing the differenced values.

Author(s)

Ben Rich <benjamin.rich@certara.com>

See Also

Examples

1
2
3
4
5
6
7
8
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)

benjaminrich/PCSmisc documentation built on May 24, 2019, 5:02 a.m.