Use this function to add a new statistic row that is a function of the other statistics in an ARD.
add_calculated_row(
x,
expr,
stat_name,
by = c(all_ard_groups(), all_ard_variables(), any_of("context")),
stat_label = stat_name,
fmt_fun = NULL,
fmt_fn = deprecated()
)(card)
data frame of class 'card'
(expression)
an expression
(string)
string naming the new statistic
(tidy-select)
Grouping variables to calculate statistics within
(string)
string of the statistic label. Default is the stat_name.
(integer, function, string)
a function of an integer or string that can be converted to a function with
alias_as_fmt_fun().
an ARD data frame of class 'card'
ard_summary(mtcars, variables = mpg) |>
add_calculated_row(expr = max - min, stat_name = "range")
#> # An ARD data frame: 9 × 8
#> variable context stat_name stat_label stat fmt_fun warning error
#> <chr> <chr> <chr> <chr> <list> <list> <list> <list>
#> 1 mpg summary N N 32 0 <NULL> <NULL>
#> 2 mpg summary mean Mean 20.1 1 <NULL> <NULL>
#> 3 mpg summary sd SD 6.03 1 <NULL> <NULL>
#> 4 mpg summary median Median 19.2 1 <NULL> <NULL>
#> 5 mpg summary p25 Q1 15.4 1 <NULL> <NULL>
#> 6 mpg summary p75 Q3 22.8 1 <NULL> <NULL>
#> 7 mpg summary min Min 10.4 1 <NULL> <NULL>
#> 8 mpg summary max Max 33.9 1 <NULL> <NULL>
#> 9 mpg summary range range 23.5 1 <NULL> <NULL>
ard_summary(mtcars, variables = mpg) |>
add_calculated_row(
expr =
dplyr::case_when(
mean > median ~ "Right Skew",
mean < median ~ "Left Skew",
.default = "Symmetric"
),
stat_name = "skew"
)
#> # An ARD data frame: 9 × 8
#> variable context stat_name stat_label stat fmt_fun warning error
#> <chr> <chr> <chr> <chr> <list> <list> <list> <list>
#> 1 mpg summary N N 32 0 <NULL> <NULL>
#> 2 mpg summary mean Mean 20.09062 1 <NULL> <NULL>
#> 3 mpg summary sd SD 6.026948 1 <NULL> <NULL>
#> 4 mpg summary median Median 19.2 1 <NULL> <NULL>
#> 5 mpg summary p25 Q1 15.35 1 <NULL> <NULL>
#> 6 mpg summary p75 Q3 22.8 1 <NULL> <NULL>
#> 7 mpg summary min Min 10.4 1 <NULL> <NULL>
#> 8 mpg summary max Max 33.9 1 <NULL> <NULL>
#> 9 mpg summary skew skew Right Skew <fn> <NULL> <NULL>