change_desc: Describe changes over a given time period

View source: R/change_desc.R

change_descR Documentation

Describe changes over a given time period

Description

Returns a character string describing whether a variable from a dataframe has either increased, decreased, or stayed the same over a given period of time.

Usage

change_desc(df, var_name, date_col, base_date, second_date)

Arguments

df

A dataframe.

var_name

The name of the variable to calculate the change for, as a string.

date_col

The name of the column containing time periods, as a string.

base_date

The base date to calculate the change between.

second_date

The second date to calculate the change between.

Value

A character object.

Examples


df <- data.frame("yrqtr" = c("2020 Q1", "2020 Q2", "2020 Q3", "2020 Q4"),
"receipts" = c(10,4,5,10)
)

change_desc(df, "receipts", "yrqtr", "2020 Q2", "2020 Q3") # returns "increased"
change_desc(df, "receipts", "yrqtr", "2020 Q1", "2020 Q2") # returns "decreased"
change_desc(df, "receipts", "yrqtr", "2020 Q1", "2020 Q4") # returns "did not change"


moj-analytical-services/mojrap documentation built on July 30, 2023, 4:43 p.m.