View source: R/utils_helpers.R
chg2pct | R Documentation |
Takes a column named 'date' and column named 'value' of a dataframe, arranges the values by date, and computes the percentage change.
chg2pct(df)
df |
a dataframe |
dataframe must have at least two columns: one named 'date' and the other named 'value'.
The percentage change over the last two time periods.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.