Learn R Programming

pointblank (version 0.7.0)

snip_stats: A fn for info_snippet(): get an inline statistical summary

Description

The snip_stats() function can be used as an info_snippet() function (i.e., provided to fn) to produce a five- or seven-number statistical summary. This inline summary works well within a paragraph of text and can help in describing the distribution of numerical values in a column.

For a given column, three different types of inline statistical summaries can be provided:

  1. a five-number summary ("5num"): minimum, Q1, median, Q3, maximum

  2. a seven-number summary ("7num"): P2, P9, Q1, median, Q3, P91, P98

  3. Bowley's seven-figure summary ("bowley"): minimum, P10, Q1, median, Q3, P90, maximum

Usage

snip_stats(column, type = c("5num", "7num", "bowley"))

Arguments

column

The name of the column that contains the target values.

type

The type of summary. By default, the "5num" keyword is used to generate a five-number summary. Two other options provide seven-number summaries: "7num" and "bowley".

Value

A formula needed for info_snippet()'s fn argument.

Function ID

3-6

See Also

Other Information Functions: info_columns(), info_section(), info_snippet(), info_tabular(), snip_highest(), snip_list(), snip_lowest()

Examples

Run this code
# NOT RUN {
# Generate an informant object, add
# a snippet with `info_snippet()`
# and `snip_stats()` (giving us a
# method to get some summary stats for
# column `a`); define a location for
# the snippet result in `{ }` and
# then `incorporate()` the snippet
# into the info text
informant <- 
  create_informant(
    read_fn = ~ small_table,
    tbl_name = "small_table",
    label = "An example."
  ) %>% 
  info_columns(
    columns = "a",
    `Stats` = "Stats (fivenum): {stats_a}."
  ) %>%
  info_snippet(
    snippet_name = "stats_a",
    fn = snip_stats(column = "a")
  ) %>%
  incorporate()

# We can print the `informant` object
# to see the information report

# }

Run the code above in your browser using DataLab