| blk.shift | R Documentation |
Shifts values up or down by a given number of positions within blocks and on selected elements.
blk.shift(x, id, shift.by = 1, ind = NULL, fill = NA)
x |
A vector in |
id |
A valid |
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 |
fill |
A value to use when no other value is appropriate. |
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.
A vector in block-format with respect to id
containing the shifted values.
Benjamin Rich <mail@benjaminrich.net>
block-format
lag
require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,] # First 4 subjects
attach(dat)
cbind(dat, SHIFT=blk.shift(time, asID(Subject), 2))
detach(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.