This function expects a data frame produced by an salic estimation function ( est_part, est_recruit, est_churn). It returns a data frame with additional formatting that allows stacking all results into a single table.

format_result(df, timeframe, group, rename_input = c("category", "year",
  "value"))

Arguments

df

data frame: Input table (3 variables) with estimated metrics

timeframe

character: value to store in the 'timeframe' variable of the output (e.g, 'full-year', 'mid-year')

group

character: value to sore in the 'group' variable of the output (e.g., 'all_sports', 'fish', 'hunt')

rename_input

character: generic names for input variables as they will appear in the output

See also

Salic Function Reference: salic

Other dashboard functions: check_threshold, est_churn, est_part, scaleup_part

Examples

library(dplyr) data(metrics) # format a table metrics$participants$res
#> # A tibble: 22 x 3 #> res year participants #> <fct> <int> <int> #> 1 Resident 2008 4768 #> 2 Resident 2009 5264 #> 3 Resident 2010 5223 #> 4 Resident 2011 5171 #> 5 Resident 2012 5341 #> 6 Resident 2013 5394 #> 7 Resident 2014 5522 #> 8 Resident 2015 5460 #> 9 Resident 2016 5332 #> 10 Resident 2017 5289 #> # ... with 12 more rows
x <- format_result(metrics$participants$res, "full-year", "all_sports") x
#> # A tibble: 22 x 7 #> timeframe group segment year category metric value #> <chr> <chr> <chr> <int> <chr> <chr> <int> #> 1 full-year all_sports Residency 2008 Resident participants 4768 #> 2 full-year all_sports Residency 2009 Resident participants 5264 #> 3 full-year all_sports Residency 2010 Resident participants 5223 #> 4 full-year all_sports Residency 2011 Resident participants 5171 #> 5 full-year all_sports Residency 2012 Resident participants 5341 #> 6 full-year all_sports Residency 2013 Resident participants 5394 #> 7 full-year all_sports Residency 2014 Resident participants 5522 #> 8 full-year all_sports Residency 2015 Resident participants 5460 #> 9 full-year all_sports Residency 2016 Resident participants 5332 #> 10 full-year all_sports Residency 2017 Resident participants 5289 #> # ... with 12 more rows
# combine formatted tables y <- format_result(metrics$participants$tot, "full-year", "all_sports") bind_rows(y, x)
#> # A tibble: 33 x 7 #> timeframe group segment year category metric value #> <chr> <chr> <chr> <int> <chr> <chr> <int> #> 1 full-year all_sports All 2008 All participants 5834 #> 2 full-year all_sports All 2009 All participants 6775 #> 3 full-year all_sports All 2010 All participants 6820 #> 4 full-year all_sports All 2011 All participants 6734 #> 5 full-year all_sports All 2012 All participants 6964 #> 6 full-year all_sports All 2013 All participants 6801 #> 7 full-year all_sports All 2014 All participants 7253 #> 8 full-year all_sports All 2015 All participants 7153 #> 9 full-year all_sports All 2016 All participants 7095 #> 10 full-year all_sports All 2017 All participants 7045 #> # ... with 23 more rows
# apply formatting across all segments x <- lapply(metrics$participants, function(x) format_result(x, "full-year", "sports")) bind_rows(x)
#> # A tibble: 110 x 7 #> timeframe group segment year category metric value #> <chr> <chr> <chr> <int> <chr> <chr> <int> #> 1 full-year sports All 2008 All participants 5834 #> 2 full-year sports All 2009 All participants 6775 #> 3 full-year sports All 2010 All participants 6820 #> 4 full-year sports All 2011 All participants 6734 #> 5 full-year sports All 2012 All participants 6964 #> 6 full-year sports All 2013 All participants 6801 #> 7 full-year sports All 2014 All participants 7253 #> 8 full-year sports All 2015 All participants 7153 #> 9 full-year sports All 2016 All participants 7095 #> 10 full-year sports All 2017 All participants 7045 #> # ... with 100 more rows
# apply across all metrics & segments bind_rows( lapply(metrics$participants, function(x) format_result(x, "full-year", "sports")), lapply(metrics$recruits, function(x) format_result(x, "full-year", "sports")), lapply(metrics$churn, function(x) format_result(x, "full-year", "sports")) )
#> # A tibble: 270 x 7 #> timeframe group segment year category metric value #> <chr> <chr> <chr> <dbl> <chr> <chr> <dbl> #> 1 full-year sports All 2008 All participants 5834 #> 2 full-year sports All 2009 All participants 6775 #> 3 full-year sports All 2010 All participants 6820 #> 4 full-year sports All 2011 All participants 6734 #> 5 full-year sports All 2012 All participants 6964 #> 6 full-year sports All 2013 All participants 6801 #> 7 full-year sports All 2014 All participants 7253 #> 8 full-year sports All 2015 All participants 7153 #> 9 full-year sports All 2016 All participants 7095 #> 10 full-year sports All 2017 All participants 7045 #> # ... with 260 more rows