skimr provides a frictionless approach to summary statistics which conforms to the principle of least surprise, displaying summary statistics the user can skim quickly to understand their data. It handles different data types and returns a skim_df object which can be included in a pipeline or displayed nicely for the human reader.

Installation

Version 2 of skimr is under very active development and near release. Version 1 is only receiving updates for significant issues. We recommend that new users interested in the development version consider installing the v2 branch.

The current released version of skimr can be installed from CRAN. If you wish to install the current build of the next release you can do so using the following:

The APIs for this branch should be considered reasonably stable but still subject to change if an issue is discovered.

To install the version with the most recent changes that have not yet been incorporated in the master branch (and may not be):

devtools::install_github("ropensci/skimr", ref = "develop")

or for version 2

devtools::install_github("ropensci/skimr", ref = "v2")

Do not rely on APIs from the develop branch.

The v2 branch is the equivalent to the develop branch for Version 2. While subject to change, we consider the APIs to be those that will be part of the version 2 release. Please visit the issue tracker for more extensive information about version 2.

Skim statistics in the console

skimr:

  • Provides a larger set of statistics than summary(), including missing, complete, n, and sd.
  • reports each data type separately.
  • handles dates, logicals, and a variety of other types
  • supports spark-bar and spark-line based on the pillar package. allows users to customize the statistics included by data type and to implement skimming for additional classes.
  • works with many Tidyverse features.

Built in support for strings, lists and other column classes

skim(dplyr::starwars)

## Skim summary statistics
##  n obs: 87 
##  n variables: 13 
## 
## ── Variable type:character ──────────────────────────────────────────────────────────────────────
##    variable missing complete  n min max empty n_unique
##   eye_color       0       87 87   3  13     0       15
##      gender       3       84 87   4  13     0        4
##  hair_color       5       82 87   4  13     0       12
##   homeworld      10       77 87   4  14     0       48
##        name       0       87 87   3  21     0       87
##  skin_color       0       87 87   3  19     0       31
##     species       5       82 87   3  14     0       37
## 
## ── Variable type:integer ────────────────────────────────────────────────────────────────────────
##  variable missing complete  n   mean    sd p0 p25 p50 p75 p100     hist
##    height       6       81 87 174.36 34.77 66 167 180 191  264 ▁▁▁▂▇▃▁▁
## 
## ── Variable type:list ───────────────────────────────────────────────────────────────────────────
##   variable missing complete  n n_unique min_length median_length max_length
##      films       0       87 87       24          1             1          7
##  starships       0       87 87       17          0             0          5
##   vehicles       0       87 87       11          0             0          2
## 
## ── Variable type:numeric ────────────────────────────────────────────────────────────────────────
##    variable missing complete  n  mean     sd p0  p25 p50  p75 p100     hist
##  birth_year      44       43 87 87.57 154.69  8 35    52 72    896 ▇▁▁▁▁▁▁▁
##        mass      28       59 87 97.31 169.46 15 55.6  79 84.5 1358 ▇▁▁▁▁▁▁▁

Handles grouped data

skim() can handle data that has been grouped using dplyr::group_by.

Knitted results

Simply skimming a data frame will produce the horizontal print layout shown above. When knitting you can also used enhanced rendering with kable and pander implementations (pander support is deprecated for v2).

Options for kable and pander

Enhanced print options are available by piping to kable() or pander(). These build on the pander package and the kable function of the knitr package These examples show how the enhanced options should appear after knitting, however your results may differ (see vignettes for details).

Note that pander support within the package is deprecated for version 2.

Option for kable.

Note that the results=‘asis’ chunk option is used and the skimr:: namespace is used to prevent it being replaced by knitr::kable (which will result in the long skim_df object being printed.)

skim(iris) %>% skimr::kable()

Skim summary statistics
n obs: 150
n variables: 5

Variable type: factor

variable missing complete n n_unique top_counts ordered
Species 0 150 150 3 set: 50, ver: 50, vir: 50, NA: 0 FALSE

Variable type: numeric

variable missing complete n mean sd p0 p25 p50 p75 p100 hist
Petal.Length 0 150 150 3.76 1.77 1 1.6 4.35 5.1 6.9 ▇▁▁▂▅▅▃▁
Petal.Width 0 150 150 1.2 0.76 0.1 0.3 1.3 1.8 2.5 ▇▁▁▅▃▃▂▂
Sepal.Length 0 150 150 5.84 0.83 4.3 5.1 5.8 6.4 7.9 ▂▇▅▇▆▅▂▂
Sepal.Width 0 150 150 3.06 0.44 2 2.8 3 3.3 4.4 ▁▂▅▇▃▂▁▁

Options for pander

At times you may need panderOptions('knitr.auto.asis', FALSE).

skim(iris) %>% pander()

Skim summary statistics
n obs: 150
n variables: 5

Table continues below
variable missing complete n n_unique
Species 0 150 150 3
top_counts ordered
set: 50, ver: 50, vir: 50, NA: 0 FALSE
Table continues below
variable missing complete n mean sd p0 p25 p50 p75
Petal.Length 0 150 150 3.76 1.77 1 1.6 4.35 5.1
Petal.Width 0 150 150 1.2 0.76 0.1 0.3 1.3 1.8
Sepal.Length 0 150 150 5.84 0.83 4.3 5.1 5.8 6.4
Sepal.Width 0 150 150 3.06 0.44 2 2.8 3 3.3
p100 hist
6.9 ▇▁▁▂▅▅▃▁
2.5 ▇▁▁▅▃▃▂▂
7.9 ▂▇▅▇▆▅▂▂
4.4 ▁▂▅▇▃▂▁▁

skim_df object (long format)

By default skim() prints beautifully in the console, but it also produces a long, tidy-format skim_df object that can be computed on.

Note that the long skimr object is not supported in version 2.

Customizing skimr

Although skimr provides opinionated defaults, it is highly customizable. Users can specify their own statistics, change the formatting of results, create statistics for new classes and develop skimmers for data structures that are not data frames.

Change formatting

skimr provides a set of default formats that allow decimals in columns to be aligned, a reasonable number of decimal places for numeric data, and a representation of dates. Users can view these with show_formats() and modify them with skim_format().

Skimming other objects

Procedures for developing skim functions for other objects are described in the vignette Supporting additional objects.

Limitations of current version

We are aware that there are issues with rendering the inline histograms and line charts in various contexts, some of which are described below.

Support for spark histograms

There are known issues with printing the spark-histogram characters when printing a data frame. For example, "▂▅▇" is printed as "<U+2582><U+2585><U+2587>". This longstanding problem originates in the low-level code for printing dataframes. While some cases have been addressed, there are, for example, reports of this issue in Emacs ESS.

This means that while skimr can render the histograms to the console and in kable(), it cannot in other circumstances. This includes:

  • rendering a skimr data frame within pander()
  • converting a skimr data frame to a vanilla R data frame, but tibbles render correctly

One workaround for showing these characters in Windows is to set the CTYPE part of your locale to Chinese/Japanese/Korean with Sys.setlocale("LC_CTYPE", "Chinese"). These values do show up by default when printing a data-frame created by skim() as a list (as.list()) or as a matrix (as.matrix()).

Printing spark histograms and line graphs in knitted documents

Spark-bar and spark-line work in the console, but may not work when you knit them to a specific document format. The same session that produces a correctly rendered HTML document may produce an incorrectly rendered PDF, for example. This issue can generally be addressed by changing fonts to one with good building block (for histograms) and Braille support (for line graphs). For example, the open font “DejaVu Sans” from the extrafont package supports these. You may also want to try wrapping your results in knitr::kable(). Please see the vignette on using fonts for details.

Displays in documents of different types will vary. For example, one user found that the font “Yu Gothic UI Semilight” produced consistent results for Microsoft Word and Libre Office Write.

Contributing

We welcome issue reports and pull requests, including potentially adding support for commonly used variable classes. However, in general, we encourage users to take advantage of skimr’s flexibility to add their own customized classes. Please see the contributing and conduct documents.

ropenci_footer