Description Usage Arguments Examples
TODO
1 | chunk.blocks(data, chunk.size, condition = "condition", day = "day", block = "block", day.chunk = "day.block", chunk = "chunk")
|
data |
|
chunk.size |
|
condition |
|
day |
|
block |
|
day.chunk |
|
chunk |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (data, chunk.size, condition = "condition", day = "day",
block = "block", day.chunk = "day.block", chunk = "chunk")
{
maximums = droplevels(aggregate(data[, block], by = list(condition = data[,
condition], day = data[, day]), max))
conditions = as.character(unique(maximums$condition))
num.days = length(unique(maximums$day))
block.max = array(dim = c(length(conditions), num.days))
index = 0
for (cond in conditions) {
index = index + 1
days = rep(0, num.days)
d = subset(maximums, condition == cond)
days[d$day + 1] = ceiling(d$x/chunk.size)
block.max[index, ] = c(0, cumsum(days)[1:(num.days -
1)])
}
rownames(block.max) = conditions
new.data = data
new.data[, day.chunk] = floor(new.data[, block]/chunk.size) +
diag(block.max[as.character(new.data[, condition]), new.data[,
day] + 1])
new.data[, chunk] = floor(new.data[, block]/chunk.size)
list(data = new.data, block.max = block.max)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.