StartEnd: Find the starting and ending time points of a spell

Description Usage Arguments Value See Also Examples

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

1
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 GroupVar is missing then .

SpellValue

a value indicating when a unit is in a spell. If SpellValue is missing then any change in Var's value will be treated as the start/end of a spell. Must specify if OnlyStart = TRUE.

OnlyStart

logical for whether or not to only add a new Spell_Start variable. Please see the details.

...

Aguments to pass to slide.

Value

a data frame. If OnlyStart = FALSE then two new variables are returned:

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

slide

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 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)

DataCombine documentation built on May 2, 2019, 11:26 a.m.