blk.findConsecutive: Finds Consecutive Rows With a Common Property

View source: R/PCSmisc.R

blk.findConsecutiveR Documentation

Finds Consecutive Rows With a Common Property

Description

Groups of consecutive rows are identified, where each row in the group has a certain property.

Usage

blk.findConsecutive(id, ind, min.consec = 2, fill = 0)

Arguments

id

A valid block-format ID.

ind

A logical vector in block-format with respect to id that designates rows in the data set for which the property holds.

min.consec

An integer specifying the minumum size of a group.

fill

A value to use when no other value is appropriate.

Details

This function operates on data sets in block-format. Some rows have a certain property as indicated by ind. This function identifies groups of rows that all possess the property, are consecutive and have a minimum size min.consec. All such groups of rows identified are assigned a unique integer ID. All remaining rows are given the value fill.

Value

An integer vector in block-format with respect to id containing a unique group ID for rows belonging to identified groups, and fill otherwise.

Author(s)

Benjamin Rich <mail@benjaminrich.net>

See Also

block-format

Examples

require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,]  # First 4 subjects
attach(dat)

cbind(dat, CONSEC=blk.findConsecutive(asID(Subject), ind=!is.na(dose), min.consec=5))

detach(dat)

benjaminrich/PCSmisc documentation built on Feb. 11, 2024, 9:25 p.m.