pivot_formatter: Formatters for 'pivot_format'

View source: R/pivot_format.R

pivot_formatterR Documentation

Formatters for pivot_format

Description

Formatters for pivot_format

Usage

pivot_formatter(
  n = round,
  p = function(x) {     paste0(round(x, 1), "%") },
  p_col = function(x) {     paste0(round(x, 1), "%") },
  p_row = function(x) {     paste0(round(x, 1), "%") }
)

Arguments

n

Function, applied to n.

p

Function, applied to p.

p_col

Function, applied to p_col.

p_row

Function, applied to p_row.

Value

a list of functions that can be use in pivot_format.

Examples

library(flexpivot)
data("nobel_laureates")

# One variable
pt <- pivot_table(nobel_laureates, rows = "category")

pivot_format(pt)
pivot_format(pt, formatter = pivot_formatter(
  n = function(x) {
    format(round(x * 100), big.mark = " ")
  }
))


# Two variable as rows
pt <- pivot_table(nobel_laureates, rows = c("category", "gender"))

pivot_format(pt)
pivot_format(pt, formatter = pivot_formatter(
  n = function(x) {
    format(round(x * 100), big.mark = " ")
  }
))



# One row, one column
pt <- pivot_table(nobel_laureates, rows = "category", cols = "gender")

pivot_format(pt)
pivot_format(pt, formatter = pivot_formatter(
  n = function(x) {
    format(round(x * 100), big.mark = " ")
  }
))


dreamRs/flexpivot documentation built on Oct. 26, 2023, 9:46 a.m.