splitLexisDT | R Documentation |
Split a Lexis
object along one time scale
(as [Epi::splitLexis]
) with speed
splitLexisDT(lex, breaks, timeScale, merge = TRUE, drop = TRUE)
lex |
a Lexis object, split or not |
breaks |
a vector of |
timeScale |
a character string; name of the time scale to split by |
merge |
logical; if |
drop |
logical; if |
splitLexisDT
is in essence a data.table version of
splitLexis
or survSplit
for splitting along a single
time scale. It requires a Lexis object as input, which may have already
been split along some time scale.
Unlike splitLexis
, splitLexisDT
drops observed time outside
the roof and floor of breaks
by default - with drop = FALSE
the functions have identical behaviour.
The Lexis
time scale variables can be of any arbitrary
format, e.g. Date
,
fractional years (see [Epi::cal.yr]
) and [get.yrs]
.
A data.table
or data.frame
(depending on options("popEpi.datatable")
; see ?popEpi
)
object expanded to accommodate split observations.
Joonas Miettinen
Other splitting functions:
lexpand()
,
splitMulti()
library(Epi)
data("sire", package = "popEpi")
x <- Lexis(data=sire[1000:1100, ],
entry = list(fot=0, per=get.yrs(dg_date), age=dg_age),
exit=list(per=get.yrs(ex_date)), exit.status=status)
BL <- list(fot=seq(0, 5, by = 3/12), per=c(2008, 2013))
x2 <- splitMulti(x, breaks = BL, drop = FALSE)
x3 <- splitLexisDT(x, breaks = BL$fot, timeScale = "fot", drop = FALSE)
x3 <- splitLexisDT(x3, breaks = BL$per, timeScale = "per", drop = FALSE)
x4 <- splitLexis(x, breaks = BL$fot, time.scale = "fot")
x4 <- splitLexis(x4, breaks = BL$per, time.scale = "per")
## all produce identical results
## using Date variables
x <- Lexis(data=sire[1000:1100, ],
entry = list(fot=0, per=dg_date, age=dg_date-bi_date),
exit=list(per=ex_date), exit.status=status)
BL <- list(fot = 0:5*365.25, per = as.Date(c("2008-01-01", "2013-01-01")))
x2 <- splitMulti(x, breaks = BL, drop = FALSE)
x3 <- splitLexisDT(x, breaks = BL$fot, timeScale = "fot", drop = FALSE)
x3 <- splitLexisDT(x3, breaks = BL$per, timeScale = "per", drop = FALSE)
## splitLexis may not work when using Dates
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.