View source: R/data_preparation.R
| join_lagged_col | R Documentation |
Turns data in which a quantity is stored twice, once in levels and once lagged in time, into the single-column form the rest of the package expects.
join_lagged_col(
df,
col,
col_lagged,
timestamp_col,
entity_col,
timestep = NULL
)
df |
Data frame with a column holding lagged values |
col |
Column with quantity not lagged |
col_lagged |
Column with the same quantity as |
timestamp_col |
Column with timestamps (e.g. years) |
entity_col |
Column with entities (e.g. countries) |
timestep |
Difference between timestamps (e.g. 10) |
Some panel data sets ship the dependent variable in two columns, the value
at time t and the value at time t-1, held side by side in the
same row. The functions in badp build the lags themselves from the
panel structure, so they need the quantity only once. This function
performs that reduction: the two columns are merged into one and the rows
are re-indexed so that no observation is lost.
The step is conditional. Data that already store the quantity once, as
economic_growth and migration_data do, pass
straight to feature_standardization and do not need this
function at all.
A data frame with two columns merged, i.e. just one column with the desired quantity is left.
feature_standardization
df <- data.frame(
year = c(2000, 2001, 2002, 2003, 2004),
country = c("A", "A", "B", "B", "C"),
gdp = c(1, 2, 3, 4, 5),
gdp_lagged = c(NA, 1, 2, 3, 4)
)
join_lagged_col(df, gdp, gdp_lagged, year, country, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.