countItems.Rd
Count number of items (permits, licenses, stamps, etc.) by group. This function will collect data from the database if using SQL backend.
countItems(df, groupVars = NULL)
df | A data frame |
---|---|
groupVars | A character vector of variable names to group by |
A data frame with columns for grouping variables and a column named
items
for number of items. Data frame is passed through
prettyData
function.
Other analysis functions: calcChurn
,
calcGenderProportion
,
calcParticipation
,
calcRecruitment
,
countCustomers
,
itemGroupCount
, sumRevenue
# Demo data: Count number of deer licenses each year between 2010 and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Deer", itemYear = c(2010, 2017)) ) %>% countItems(c("itemYear", "itemType"))#> # A tibble: 8 x 3 #> itemYear itemType items #> <fct> <fct> <int> #> 1 2010 Deer 1698 #> 2 2011 Deer 1678 #> 3 2012 Deer 1411 #> 4 2013 Deer 1438 #> 5 2014 Deer 1463 #> 6 2015 Deer 1541 #> 7 2016 Deer 1553 #> 8 2017 Deer 1461if (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 deer licenses each year between 2010 and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Deer", itemYear = c(2010, 2017)) ) %>% countItems(c("itemYear", "itemType")) }