This function calculates the percentage change of a specified variable from the previous year and assigns the same attributes from the original variable to the new one.

ecodata_compute_pctchange(
  data,
  variable,
  new_variable = NULL,
  units = "Percent"
)

Arguments

data

A data frame containing a "Date" column and the variable of interest.

variable

A string specifying the name of the original variable.

new_variable

Optional, a string specifying the name of the new variable to store the percentage change. Default will be based on original variable name.

units

Optional, a string specifying the units for the new variable. Default is "Percent"

Value

An ecodata data frame with the new variable containing the percentage change, with attributes copied.