Count number of customers by group. This function will collect data from the database if using SQL backend.

countCustomers(df, groupVars = NULL)

Arguments

df

A data frame with a column named customerUID

groupVars

A character vector of variable names to group by

Value

A data frame with columns for grouping variables and a column named customers for number of customers Data frame is passed through prettyData function.

See also

Examples

# Demo data: Count number of customers each year purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% countCustomers(c("itemYear", "itemType"))
#> # A tibble: 8 x 3 #> itemYear itemType customers #> <fct> <fct> <int> #> 1 2010 Fish 1628 #> 2 2011 Fish 1608 #> 3 2012 Fish 1873 #> 4 2013 Fish 1755 #> 5 2014 Fish 1786 #> 6 2015 Fish 1793 #> 7 2016 Fish 1868 #> 8 2017 Fish 1738
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: Count number of customers each year purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% countCustomers(c("itemYear", "itemType")) }