Skip to content
Snippets Groups Projects
Commit 80fe2b68 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

New function: mT.switchover - transition from one table to another either at...

New function: mT.switchover - transition from one table to another either at fixed age or by the given weights
parent 9f90ca65
No related branches found
No related tags found
No related merge requests found
......@@ -334,6 +334,28 @@ pT.getSubTable = function(table, subtable = "qx") {
NULL
}
#' @export
mT.switchover = function(table, to, at, weights = NULL) {
if (is.array(table)) {
return(array(
lapply(table, mT.switchover, to = to, at = at, weights = weights),
dim = dim(table), dimnames = dimnames(table))
)
} else if (is.list(table)) {
return(lapply(table, mT.switchover, to = to, at = at, weights = weights))
}
if (!is(table, "mortalityTable"))
stop("First argument must be a mortalityTable or a list of mortalityTable objects.")
if (is.null(weights)) {
ags.table = ages(table)
ags.to = ages(to)
weights = 1 * (ags.to >= at)
}
table@deathProbs = table@deathProbs * (1 - weights) + to@deathProbs * weights
table
}
#' @exportMethod mT.round
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment