sumRevenue.Rd
Calculate total revenue by group. Total revenue is the sum price variable.
sumRevenue(df, groupVars = NULL)
df | A data frame |
---|---|
groupVars | A character vector of variable names to group by |
A dataframe with columns for grouping variables and a column named revenue for total revenue
Other analysis functions: calcChurn
,
calcGenderProportion
,
calcParticipation
,
calcRecruitment
,
countCustomers
, countItems
,
itemGroupCount
# Demo data: Calculate revenue each year from fishing licenses between 2010 # and 2017 filterData( dataSource = "csv", activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% sumRevenue(c("itemYear", "itemType"))#> # A tibble: 8 x 3 #> itemYear itemType revenue #> <fct> <fct> <dbl> #> 1 2010 Fish 30774 #> 2 2011 Fish 31100. #> 3 2012 Fish 37631. #> 4 2013 Fish 35274. #> 5 2014 Fish 35642. #> 6 2015 Fish 34204. #> 7 2016 Fish 40332. #> 8 2017 Fish 42917if (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: Calculate revenue each year from fishing licenses between 2010 # and 2017 filterData( dataSource = "sql", conn = myConn, activeFilters = list(itemType = "Fish", itemYear = c(2010, 2017)) ) %>% sumRevenue(c("itemYear", "itemType")) }