| blk.count | R Documentation |
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.
blk.count(id, id2=id, ind = NULL)
id |
A valid |
id2 |
A valid |
ind |
A vector of logicals specifying the rows that satisfy the criterion. |
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.
If id2 is NULL,
a vector containing one value for
each level of id. Otherwise,
a vectors in block-format with respect to id2.
Benjamin Rich <mail@benjaminrich.net>
block-format
blk.singleValue and blk.repeatValue
tapply
### 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.