View source: R/data_preparation.R
join_lagged_col | R Documentation |
This function allows to turn data in the format with lagged values for a chosen column (i.e. there are two columns with the same quantity, but one column is lagged in time) into the format with just one column
join_lagged_col(
df,
col,
col_lagged,
timestamp_col,
entity_col,
timestep = NULL
)
df |
Dataframe with data with a column with 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) |
A dataframe with two columns merged, i.e. just one column with the desired quantity is left.
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.