blk.shift: Shift Values Respecting Block Boundaries

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

Description

Shifts values up or down by a given number of positions within blocks and on selected elements.

Usage

1
blk.shift(x, id, shift.by = 1, ind = NULL, fill = NA)

Arguments

x

A vector in block-format with respect to id.

id

A valid block-format ID.

shift.by

An integer specifying the number of positions to shift by. Can be positive (shift down) or negative (shift up).

ind

A logical vector that designates a subset of x to use. By default all are selected.

fill

A value to use when no other value is appropriate.

Details

This function operates on data sets in block-format. The number of positions by which to shift by may be positive or negative, with positive indicating downwards in the data set and negative upwards. 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. Shifting creates ‘gaps’ at the start (or end if shift.by is negative) of a block. The gaps are filled with the value fill so that the result is in block-format with respect to id.

Value

A vector in block-format with respect to id containing the shifted 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, SHIFT=blk.shift(time, asID(Subject), 2))

detach(dat)

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