set_denoms_by {Tplyr} | R Documentation |
Set variables used in pct denominator calculation
Description
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.
Usage
set_denoms_by(e, ...)
Arguments
e |
A count/shift layer object |
... |
Unquoted variable names |
Value
The modified layer object
Examples
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()
[Package Tplyr version 1.2.1 Index]