Learn R Programming

modelsummary (version 1.1.0)

datasummary_correlation_format: Format the content of a correlation table

Description

Mostly for internal use, but can be useful when users supply a function to the method argument of datasummary_correlation.

Usage

datasummary_correlation_format(
  x,
  fmt,
  leading_zero = FALSE,
  diagonal = NULL,
  upper_triangle = NULL
)

Arguments

x

square numeric matrix

fmt

determines how to format numeric values

  • integer: the number of digits to keep after the period format(round(x, fmt), nsmall=fmt)

  • character: passed to the sprintf function (e.g., '%.3f' keeps 3 digits with trailing zero). See ?sprintf

  • function: returns a formatted character string.

  • NULL: does not format numbers, which allows users to include function in the "glue" strings in the estimate and statistic arguments.

leading_zero

boolean. If FALSE, leading zeros are removed

diagonal

character or NULL. If character, all elements of the diagonal are replaced by the same character (e.g., "1").

upper_triangle

character or NULL. If character, all elements of the upper triangle are replaced by the same character (e.g., "" or ".").

Examples

Run this code
library(modelsummary)

dat <- mtcars[, c("mpg", "hp", "disp")]

cor_fun <- function(x) {
  out <- cor(x, method = "kendall")
  datasummary_correlation_format(
    out,
    fmt = 2,
    upper_triangle = "x",
    diagonal = ".")
}

datasummary_correlation(dat, method = cor_fun)

Run the code above in your browser using DataLab