calculate_percentage_change.Rd
Calculate percentage change over a time period for the given column pattern.
calculate_percentage_change(
df,
pattern,
compare_period = c(2, 2),
time_filter = NULL
)
A tibble or Data frame
A string representing column pattern
A numeric vector of comparison period
A numeric vector of time filter
A vector with calculated percentage change
This function aims to generate features such as percentage change in last month versus last to last month to capture trend in data for a given comparison period. For example, In Telecommunication it can be used to generate features useful for predicting subscribers who are more likely to decline their revenue next month/week. In Finance it can be used to generate features useful for predicting customers who are going to default next month/week.
df <- data.frame(
week_payment1 = c(1, 2, 3),
week_payment2 = c(4, 5, 6),
week_payment3 = c(7, 8, 9),
week_payment4 = c(10, 11, 12)
)
calculate_percentage_change(df, "week_payment")
#> [1] -70.58824 -63.15789 -57.14286