addPeriods | R Documentation |
Create longitudinal/panel data
addPeriods(
dtName,
nPeriods = NULL,
idvars = "id",
timevars = NULL,
timevarName = "timevar",
timeid = "timeID",
perName = "period"
)
dtName |
Name of existing data table |
nPeriods |
Number of time periods for each record |
idvars |
Names of index variables (in a string vector) that will be repeated during each time period |
timevars |
Names of time dependent variables. Defaults to NULL. |
timevarName |
Name of new time dependent variable |
timeid |
Variable name for new index field. Defaults to "timevar" |
perName |
Variable name for period field. Defaults to "period" |
An updated data.table that that has multiple rows per observation in dtName
tdef <- defData(varname = "T", dist = "binary", formula = 0.5)
tdef <- defData(tdef, varname = "Y0", dist = "normal", formula = 10, variance = 1)
tdef <- defData(tdef, varname = "Y1", dist = "normal", formula = "Y0 + 5 + 5 * T", variance = 1)
tdef <- defData(tdef, varname = "Y2", dist = "normal", formula = "Y0 + 10 + 5 * T", variance = 1)
dtTrial <- genData(5, tdef)
dtTrial
dtTime <- addPeriods(dtTrial,
nPeriods = 3, idvars = "id",
timevars = c("Y0", "Y1", "Y2"), timevarName = "Y"
)
dtTime
# Varying # of periods and intervals - need to have variables
# called nCount and mInterval
def <- defData(varname = "xbase", dist = "normal", formula = 20, variance = 3)
def <- defData(def, varname = "nCount", dist = "noZeroPoisson", formula = 6)
def <- defData(def, varname = "mInterval", dist = "gamma", formula = 30, variance = .01)
def <- defData(def, varname = "vInterval", dist = "nonrandom", formula = .07)
dt <- genData(200, def)
dt[id %in% c(8, 121)]
dtPeriod <- addPeriods(dt)
dtPeriod[id %in% c(8, 121)] # View individuals 8 and 121 only
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.