Description Usage Arguments See Also Examples
Calculate participation rate by group. Participation rate is the number of customers divided by the population size.
1 | calcParticipation(df, groupVars, pop)
|
df |
A data frame |
groupVars |
A character vector of variable names to group by |
pop |
A dataframe of population by county, year, gender, and age group. |
Other analysis functions: calcChurn
,
calcGenderProportion
,
calcRecruitment
,
countCustomers
, countItems
,
itemGroupCount
, sumRevenue
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Get list of valid counties (used to filter out data entry errors)
validCounties <- countyMaps %>%
dplyr::filter(region == "nebraska") %>%
dplyr::distinct(county) %>%
dplyr::pull(county)
# Demo data: Participation rate for customers purchasing a fishing
# license between 2010 and 2017
filterData(
dataSource = "csv",
activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017), state = "NE")
) %>%
calcParticipation(c("itemType", "county"),
pop = statePop %>% filter(state == "NE")
) %>%
dplyr::filter(county %in% validCounties)
## Not run:
# 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
# Get list of valid counties (used to filter out data entry errors)
validCounties <- countyMaps %>%
dplyr::filter(region == "nebraska") %>%
dplyr::distinct(county) %>%
dplyr::pull(county)
# SQL Backend: Participation rate for customers purchasing a fishing
# license between 2010 and 2017
filterData(
dataSource = "sql",
conn = myConn,
activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017), state = "NE")
) %>%
calcParticipation(c("itemType", "county"),
pop = statePop %>% filter(state == "NE")
) %>%
dplyr::filter(county %in% validCounties)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.