Skip to contents

Produces a compact summary of a data.frame. Each row of the result describes one column of the input with a type-specific synopsis.

Supported types and their summaries:

  • numeric / integer: count of non-NA values, min and max.

  • character: number of unique values, first values listed.

  • factor: number of levels, levels listed.

  • logical: count of non-NA values, counts of TRUE and FALSE.

  • Date: count of non-NA values, date range.

  • POSIXct / POSIXlt: count of non-NA values, datetime range.

  • hms / difftime: count of non-NA values, time range.

Character and factor columns share the same summary layout but report a different type label.

The result has class "compact_summary" and can be converted into a flextable with as_flextable().

Usage

compact_summary(x, show_type = FALSE, show_na = FALSE, max_levels = 10L)

Arguments

x

A data.frame.

show_type

If TRUE, a Type column is added when the object is rendered as a flextable.

show_na

If TRUE, a NA column showing the count of missing values per column is added when rendered as a flextable.

max_levels

Maximum number of levels or unique values displayed for factor and character columns. Additional values are replaced by ", ...".

Value

A data.frame with additional class "compact_summary".

Examples

z <- compact_summary(iris)
as_flextable(z)

Column

N

Values

Sepal.Length

150

Min: 4.3, Max: 7.9

Sepal.Width

150

Min: 2.0, Max: 4.4

Petal.Length

150

Min: 1.0, Max: 6.9

Petal.Width

150

Min: 0.1, Max: 2.5

Species

3

'setosa', 'versicolor', 'virginica'

z <- compact_summary(iris, show_type = TRUE, show_na = TRUE) as_flextable(z)

Column

Type

N

NA

Values

Sepal.Length

numeric

150

0

Min: 4.3, Max: 7.9

Sepal.Width

numeric

150

0

Min: 2.0, Max: 4.4

Petal.Length

numeric

150

0

Min: 1.0, Max: 6.9

Petal.Width

numeric

150

0

Min: 0.1, Max: 2.5

Species

factor

3

0

'setosa', 'versicolor', 'virginica'