change_desc | R Documentation |
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.
change_desc(df, var_name, date_col, base_date, second_date)
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. |
A character object.
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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.