View source: R/shift_bindings.R
set_denoms_by | R Documentation |
This function is used when calculating pct in count or shift layers. The percentages default to the treatment variable and any column variables but can be calculated on any variables passed to target_var, treat_var, by, or cols.
set_denoms_by(e, ...)
e |
A count/shift layer object |
... |
Unquoted variable names |
The modified layer object
library(magrittr)
# Default has matrix of treatment group, additional columns,
# and by variables sum to 1
tplyr_table(mtcars, am) %>%
add_layer(
group_shift(vars(row=gear, column=carb), by=cyl) %>%
set_format_strings(f_str("xxx (xx.xx%)", n, pct))
) %>%
build()
tplyr_table(mtcars, am) %>%
add_layer(
group_shift(vars(row=gear, column=carb), by=cyl) %>%
set_format_strings(f_str("xxx (xx.xx%)", n, pct)) %>%
set_denoms_by(cyl, gear) # Row % sums to 1
) %>%
build()
tplyr_table(mtcars, am) %>%
add_layer(
group_shift(vars(row=gear, column=carb), by=cyl) %>%
set_format_strings(f_str("xxx (xx.xx%)", n, pct)) %>%
set_denoms_by(cyl, gear, am) # % within treatment group sums to 1
) %>%
build()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.