| blk.indicators | R Documentation |
Functions that return indicators (logical vectors) indicating rows in a data set that match a criterion.
blk.firstOnly(id, ind = NULL)
blk.lastOnly(id, ind = NULL)
blk.onlyFirst(id, ind = NULL)
blk.onlyLast(id, ind = NULL)
blk.untilFirst(id, ind, include.first = TRUE, fill = FALSE)
blk.firstOnwards(id, ind, include.first = TRUE, fill = FALSE)
blk.untilLast(id, ind, include.last = TRUE, fill = FALSE)
blk.lastOnwards(id, ind, include.last = TRUE, fill = FALSE)
id |
A valid |
ind |
A logical vector in |
include.first |
A logical. Should the first matching row itself be included? |
include.last |
A logical. Should the last matching row itself be included? |
fill |
A value to use when no other value is appropriate. |
These functions operate on data sets in block-format.
blk.firstOnly selects the first element of each block for which ind is TRUE.
blk.onlyFirst is an alias.
blk.lastOnly selects the last element of each block for which ind is TRUE.
blk.onlyLast is an alias.
Setting ind to NULL is equivalent to setting ind =
rep(TRUE, length(id)), so the first or last row of each block is selected.
blk.untilFirst selects all elements from the start of each block until
the first element of the block for which ind is TRUE. Whether
or not that element itself is selected is controlled by include.first.
blk.firstOnwards is similar, but it selects all rows from the first
element of each block for which ind is TRUE to the end of the
block. blk.untilLast and blk.lastOnwards are similar,
selecting all elements from the start of the block to the last element for
which ind is TRUE, and all elements from this one to the end of
the block repectively (including the last element for which ind is
TRUE if include.last is FALSE, and excluding it otherwise).
An indicator vector (logical) block-format with respect to id that indicates the elements selected.
Benjamin Rich <mail@benjaminrich.net>
block-format
require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,] # First 4 subjects
attach(dat)
cbind(dat, IND=blk.firstOnly(asID(Subject), !is.na(conc)))
cbind(dat, IND=blk.lastOnly(asID(Subject), !is.na(conc)))
cbind(dat, IND=blk.untilFirst(asID(Subject), !is.na(conc)))
cbind(dat, IND=blk.untilFirst(asID(Subject), !is.na(conc), FALSE))
cbind(dat, IND=blk.firstOnwards(asID(Subject), !is.na(conc)))
cbind(dat, IND=blk.firstOnwards(asID(Subject), !is.na(conc), FALSE))
cbind(dat, IND=blk.untilLast(asID(Subject), !is.na(dose)))
cbind(dat, IND=blk.untilLast(asID(Subject), !is.na(dose), FALSE))
cbind(dat, IND=blk.lastOnwards(asID(Subject), !is.na(dose)))
cbind(dat, IND=blk.lastOnwards(asID(Subject), !is.na(dose), FALSE))
detach(dat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.