join_lagged_col: Dataframe with no lagged column

View source: R/data_preparation.R

join_lagged_colR Documentation

Dataframe with no lagged column

Description

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

Usage

join_lagged_col(
  df,
  col,
  col_lagged,
  timestamp_col,
  entity_col,
  timestep = NULL
)

Arguments

df

Dataframe with data with a column with lagged values

col

Column with quantity not lagged

col_lagged

Column with the same quantity as col, but the values are lagged in time

timestamp_col

Column with timestamps (e.g. years)

entity_col

Column with entities (e.g. countries)

timestep

Difference between timestamps (e.g. 10)

Value

A dataframe with two columns merged, i.e. just one column with the desired quantity is left.

Examples

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)


bdsm documentation built on April 4, 2025, 1:06 a.m.