blk.count: Blockwise Count

View source: R/PCSmisc.R

blk.countR Documentation

Blockwise Count

Description

Given a data set in block-format, determine the block sizes or count the number of rows in each block that matche a given criterion.

Usage

  blk.count(id, id2=id, ind = NULL)

Arguments

id

A valid block-format ID.

id2

A valid block-format ID for the return value, or NULL

ind

A vector of logicals specifying the rows that satisfy the criterion.

Details

The parameter id2 determines the return value. If id2 is NULL, the returned vector contains one element for each level of id, with fill used for blocks of size zero.

Value

If id2 is NULL, a vector containing one value for each level of id. Otherwise, a vectors in block-format with respect to id2.

Author(s)

Benjamin Rich <mail@benjaminrich.net>

See Also

  • block-format

  • blk.singleValue and blk.repeatValue

  • tapply

Examples


### The size of each block (example)
id <- factor(c("A", "A", "C", "C", "C"), levels=c("A", "B", "C"))
blk.count(id, NULL)  # Note that "B" is a valid ID.  The corresponding block has size zero.

require(nlme)
data(Phenobarb)
dat <- Phenobarb[1:56,]  # First 4 subjects
dat$ID <- asID(dat$Subject)

attach(dat)

# Count the number of times concentration was observed for each subject
blk.count(ID, NULL, ind=(!is.na(conc)))

# Count the number of times concentration was observed for each
# subject and repeat it on each row of the data.frame
dat$count.conc <- blk.count(ID, ind=(!is.na(conc)))
dat

detach(dat)


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