Description Usage Arguments Value Examples
View source: R/add_diff_variable.R
Differences multiple variables (either exactly or partially defined) by another variable for a specified lag and stratification.
1 2 3 4 5 6 7 8 9 10 11 12 |
dt |
A |
variable |
Character string identifying the variable in target to calculate the lagged difference for. |
label |
Character string giving the name for the new lagged variable. |
by |
An optional character vector identifying the variables to stratify by. |
shift_var |
Character string, indicating the variable to use to calculate the difference. |
vars |
Character vector giving the exact names of variables to calculate the difference for. |
partial_vars |
Character vector giving the partial names of variables to calculate the difference for. |
fill |
Value to use for padding when the window goes beyond the input length. |
n |
integer vector denoting the offset by which to lead or lag the input. To create multiple lead/lag vectors, provide multiple values to |
type |
default is |
The input data.table
combined with the new differenced
variable.
1 2 3 4 | dt <- data.frame(target = "test", var = 1:100, var2 = c(1, 2),
strat = c("a", "b"))
add_diff_variable(dt, "test", "new", vars = "var", shift_var = "var2",
by = "strat")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.