SpreadDummy {DataCombine} | R Documentation |
Spread a dummy variable (1's and 0') over a specified time period and for specified groups
Description
Spread a dummy variable (1's and 0') over a specified time period and for specified groups
Usage
SpreadDummy(data, Var, GroupVar, NewVar, spreadBy = -2, reminder = TRUE)
Arguments
data |
a data frame object. |
Var |
a character string naming the numeric dummy variable with values 0 and 1 that you would like to spread. Can be either spread as a lag or lead. |
GroupVar |
a character string naming the variable grouping the units
within which |
NewVar |
a character string specifying the name for the new variable to place the spread dummy data in. |
spreadBy |
numeric value specifying how many rows (time units) to spread the data over. Negative values spread the data down–lag the data. Positive values spread the data up–lead the data. |
reminder |
logical. Whether or not to remind you to order your data by
the |
See Also
Examples
# Create dummy data
ID <- sort(rep(seq(1:4), 5))
NotVar <- rep(1:5, 4)
Dummy <- sample(c(0, 1), size = 20, replace = TRUE)
Data <- data.frame(ID, NotVar, Dummy)
# Spread
DataSpread1 <- SpreadDummy(data = Data, Var = 'Dummy',
spreadBy = 2, reminder = FALSE)
DataSpread2 <- SpreadDummy(data = Data, Var = 'Dummy', GroupVar = 'ID',
spreadBy = -2)