StartEnd {DataCombine} | R Documentation |
Find the starting and ending time points of a spell
Description
StartEnd
finds the starting and ending time points of a spell,
including for time-series cross-sectional data. Note: your data needs to be
sorted by date. The date should be ascending (i.e. increasing as it moves
down the rows).
Usage
StartEnd(data, SpellVar, GroupVar, SpellValue, OnlyStart = FALSE, ...)
Arguments
data |
a data frame object. |
SpellVar |
a character string naming the variable with information on when each spell starts. |
GroupVar |
a character string naming the variable grouping the units
experiencing the spells. If |
SpellValue |
a value indicating when a unit is in a spell. If
|
OnlyStart |
logical for whether or not to only add a new
|
... |
Aguments to pass to |
Value
a data frame. If OnlyStart = FALSE
then two new variables are
returned:
Spell_Start: The time period year of a given spell.
Spell_End: The end time period of a given spell.
If OnlyStart = TRUE
then only Spell_Start
is added.
This variable includes both 1
's for the start of a new spell and for
the start of a 'gap spell', i.e. a spell after Spell_End
.
See Also
Examples
# Create fake data
ID <- sort(rep(seq(1:4), 5))
Time <- rep(1:5, 4)
Dummy <- c(1, sample(c(0, 1), size = 19, replace = TRUE))
Data <- data.frame(ID, Time, Dummy)
# Find start/end of spells denoted by Dummy = 1
DataSpell <- StartEnd(Data, SpellVar = 'Dummy', GroupVar = 'ID',
TimeVar = 'Time', SpellValue = 1)
head(DataSpell)