blk.count: Blockwise Count

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

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

1
  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)

Ben Rich <benjamin.rich@certara.com>

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
### 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 May 24, 2019, 5:02 a.m.