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 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

# 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)


[Package DataCombine version 0.2.21 Index]