chg2pct: Convert last two values in a series and convert them to a...

View source: R/utils_helpers.R

chg2pctR Documentation

Convert last two values in a series and convert them to a percent increase or decrease

Description

Takes a column named 'date' and column named 'value' of a dataframe, arranges the values by date, and computes the percentage change.

Usage

chg2pct(df)

Arguments

df

a dataframe

Details

dataframe must have at least two columns: one named 'date' and the other named 'value'.

Value

The percentage change over the last two time periods.

Examples

## Not run: 
# positive result
pos_data_set <- data.frame(date = as.Date(c("2020-01-01",
"2020-02-01", "2020-03-01" )), value = c(1, 1.1, 1.2))
# negative result
neg_data_set <- data.frame(date = as.Date(c(
"2020-01-01", "2020-02-01", "2020-03-01")), value = c(1, 1.1, 1.0))

chg2pct(pos_data_set)
chg2pct(neg_data_set)

## End(Not run)

RobWiederstein/econdash documentation built on Oct. 2, 2022, 3:42 a.m.