Calculate recruitment using a variable window size

calcRecruitment(df, groupVars = NULL, birthThreshold = 5)

Arguments

df

A data frame

groupVars

A character vector of variable names to group by

birthThreshold

A numeric value indicating how many years without purchase before an individual is considered a recruit

Value

A dataframe with columns for grouping variables and columns for totalCustomers, retainedCustomers, recruitedCustomers, and recruitementRate

See also

Examples

# Demo data: Recruitment for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcRecruitment(c("itemType"))
#> # A tibble: 3 x 6 #> itemYear itemType recruitedCustom… retainedCustome… totalCustomers #> <fct> <fct> <dbl> <dbl> <dbl> #> 1 2015 Fish 591 1202 1793 #> 2 2016 Fish 640 1228 1868 #> 3 2017 Fish 520 1218 1738 #> # … with 1 more variable: recruitmentRate <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: Recruitment for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcRecruitment(c("itemType")) }