Learn R Programming

cards (version 0.5.1)

add_calculated_row: Add Calculated Row

Description

Use this function to add a new statistic row that is a function of the other statistics in an ARD.

Usage

add_calculated_row(
  x,
  expr,
  stat_name,
  by = c(all_ard_groups(), all_ard_variables(), any_of("context")),
  stat_label = stat_name,
  fmt_fn = NULL
)

Value

an ARD data frame of class 'card'

Arguments

x

(card)
data frame of class 'card'

expr

(expression)
an expression

stat_name

(string)
string naming the new statistic

by

(tidy-select)
Grouping variables to calculate statistics within

stat_label

(string)
string of the statistic label. Default is the stat_name.

fmt_fn

(integer, function, string)
a function of an integer or string that can be converted to a function with alias_as_fmt_fn().

Examples

Run this code
ard_continuous(mtcars, variables = mpg) |>
  add_calculated_row(expr = max - min, stat_name = "range")

ard_continuous(mtcars, variables = mpg) |>
  add_calculated_row(
    expr =
      dplyr::case_when(
        mean > median ~ "Right Skew",
        mean < median ~ "Left Skew",
        .default = "Symmetric"
      ),
    stat_name = "skew"
  )

Run the code above in your browser using DataLab