Calculate churn using variable window size

calcChurn(df, groupVars = NULL, deathThreshold = 5)

Arguments

df

A data frame

groupVars

A character vector of variable names to group by

deathThreshold

A numeric value indicating how many years must elapse before an individual is considered churned

Value

A dataframe with columns for grouping variables and columns churnedCustomers, retainedCustomers, totalCustomers, churnRate, and retentionRate

See also

Examples

# Demo data: Churn for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcChurn(c("itemType"))
#> # A tibble: 3 x 7 #> itemYear itemType churnedCustomers retainedCustome… totalCustomers churnRate #> <fct> <fct> <dbl> <dbl> <dbl> <dbl> #> 1 2010 Fish 490 1138 1628 0.301 #> 2 2011 Fish 488 1120 1608 0.303 #> 3 2012 Fish 594 1279 1873 0.317 #> # … with 1 more variable: retentionRate <dbl>
if (FALSE) { # Database connection. Suggest using keyring package to avoid hardcoding # passwords myConn <- DBI::dbConnect(odbc::odbc(), dsn = "HuntFishApp", # Your datasource name uid = keyring::key_get("HuntFishAppUID"), # Your username pwd = keyring::key_get("HuntFishAppPWD") ) # Your password # SQL Backend: Churn for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcChurn(c("itemType")) }