Calculate gender proportion by group. This function collects data from the database.

calcGenderProportion(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 dataframe with columns for grouping variables and a column named genderProportion for gender proportion. Data frame is passed through prettyData function.

See also

Examples

# Demo data: Gender proportions for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcGenderProportion(c("itemYear", "itemType"))
#> # A tibble: 16 x 5 #> gender itemYear itemType customers genderProportion #> <fct> <fct> <fct> <int> <dbl> #> 1 Female 2010 Fish 385 0.236 #> 2 Female 2011 Fish 389 0.242 #> 3 Female 2012 Fish 455 0.243 #> 4 Female 2013 Fish 474 0.270 #> 5 Female 2014 Fish 494 0.277 #> 6 Female 2015 Fish 491 0.274 #> 7 Female 2016 Fish 522 0.279 #> 8 Female 2017 Fish 495 0.285 #> 9 Male 2010 Fish 1243 0.764 #> 10 Male 2011 Fish 1219 0.758 #> 11 Male 2012 Fish 1418 0.757 #> 12 Male 2013 Fish 1281 0.730 #> 13 Male 2014 Fish 1292 0.723 #> 14 Male 2015 Fish 1302 0.726 #> 15 Male 2016 Fish 1346 0.721 #> 16 Male 2017 Fish 1243 0.715
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: Gender proportions for customers purchasing a fishing # license between 2010 and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% calcGenderProportion(c("itemYear", "itemType")) }