Description Usage Arguments Examples
CountSpell
is a function that returns a variable counting the spell
number for an observation. Works with grouped data.
1 | CountSpell(data, TimeVar, SpellVar, GroupVar, NewVar, SpellValue)
|
data |
a data frame object. |
TimeVar |
a character string naming the time variable. |
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. |
NewVar |
NewVar a character string naming the new variable to place the spell counts in. |
SpellValue |
a value indicating when a unit is in a spell. Must match
the class of the |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Create fake data
ID <- sort(rep(seq(1:4), 5))
Time <- rep(1:20)
Dummy <- c(1, sample(c(0, 1), size = 19, replace = TRUE))
Data <- data.frame(ID, Time, Dummy)
# Find spell for whole data frame
DataSpell1 <- CountSpell(Data, TimeVar = 'Time', SpellVar = 'Dummy',
SpellValue = 1)
head(DataSpell1)
# Find spell for each ID group
DataSpell2 <- CountSpell(Data, TimeVar = 'Time', SpellVar = 'Dummy',
GroupVar = 'ID', SpellValue = 1)
head(DataSpell2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.