Debian Codegraph @

vignettes/skimr.html

raw symbols SCIP
1 <!DOCTYPE html>
2
3 <html>
4
5 <head>
6
7 <meta charset="utf-8" />
8 <meta name="generator" content="pandoc" />
9 <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
10
11 <meta name="viewport" content="width=device-width, initial-scale=1" />
12
13
14 <meta name="date" content="2020-04-03" />
15
16 <title>Using Skimr</title>
17
18
19
20 <style type="text/css">code{white-space: pre;}</style>
21 <style type="text/css" data-origin="pandoc">
22 div.sourceCode { overflow-x: auto; }
23 table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
24 margin: 0; padding: 0; vertical-align: baseline; border: none; }
25 table.sourceCode { width: 100%; line-height: 100%; }
26 td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
27 td.sourceCode { padding-left: 5px; }
28 code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
29 code > span.dt { color: #902000; } /* DataType */
30 code > span.dv { color: #40a070; } /* DecVal */
31 code > span.bn { color: #40a070; } /* BaseN */
32 code > span.fl { color: #40a070; } /* Float */
33 code > span.ch { color: #4070a0; } /* Char */
34 code > span.st { color: #4070a0; } /* String */
35 code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
36 code > span.ot { color: #007020; } /* Other */
37 code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
38 code > span.fu { color: #06287e; } /* Function */
39 code > span.er { color: #ff0000; font-weight: bold; } /* Error */
40 code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
41 code > span.cn { color: #880000; } /* Constant */
42 code > span.sc { color: #4070a0; } /* SpecialChar */
43 code > span.vs { color: #4070a0; } /* VerbatimString */
44 code > span.ss { color: #bb6688; } /* SpecialString */
45 code > span.im { } /* Import */
46 code > span.va { color: #19177c; } /* Variable */
47 code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
48 code > span.op { color: #666666; } /* Operator */
49 code > span.bu { } /* BuiltIn */
50 code > span.ex { } /* Extension */
51 code > span.pp { color: #bc7a00; } /* Preprocessor */
52 code > span.at { color: #7d9029; } /* Attribute */
53 code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
54 code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
55 code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
56 code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
57
58 </style>
59 <script>
60 // apply pandoc div.sourceCode style to pre.sourceCode instead
61 (function() {
62 var sheets = document.styleSheets;
63 for (var i = 0; i < sheets.length; i++) {
64 if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
65 try { var rules = sheets[i].cssRules; } catch (e) { continue; }
66 for (var j = 0; j < rules.length; j++) {
67 var rule = rules[j];
68 // check if there is a div.sourceCode rule
69 if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
70 var style = rule.style.cssText;
71 // check if color or background-color is set
72 if (rule.style.color === '' && rule.style.backgroundColor === '') continue;
73 // replace div.sourceCode by a pre.sourceCode rule
74 sheets[i].deleteRule(j);
75 sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
76 }
77 }
78 })();
79 </script>
80
81
82
83 <link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" rel="stylesheet" type="text/css" />
84
85
86
87
88 </head>
89
90 <body>
91
92
93
94
95 <h1 class="title toc-ignore">Using Skimr</h1>
96 <h4 class="date">2020-04-03</h4>
97
98
99
100 <div id="introduction" class="section level2">
101 <h2>Introduction</h2>
102 <p><code>skimr</code> is designed to provide summary statistics about variables. It is opinionated in its defaults, but easy to modify.</p>
103 <p>In base R, the most similar functions are <code>summary()</code> for vectors and data frames and <code>fivenum()</code> for numeric vectors:</p>
104 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(iris)</code></pre></div>
105 <pre><code>## Sepal.Length Sepal.Width Petal.Length Petal.Width
106 ## Min. :4.300 Min. :2.000 Min. :1.000 Min. :0.100
107 ## 1st Qu.:5.100 1st Qu.:2.800 1st Qu.:1.600 1st Qu.:0.300
108 ## Median :5.800 Median :3.000 Median :4.350 Median :1.300
109 ## Mean :5.843 Mean :3.057 Mean :3.758 Mean :1.199
110 ## 3rd Qu.:6.400 3rd Qu.:3.300 3rd Qu.:5.100 3rd Qu.:1.800
111 ## Max. :7.900 Max. :4.400 Max. :6.900 Max. :2.500
112 ## Species
113 ## setosa :50
114 ## versicolor:50
115 ## virginica :50
116 ##
117 ##
118 ## </code></pre>
119 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(iris<span class="op">$</span>Sepal.Length)</code></pre></div>
120 <pre><code>## Min. 1st Qu. Median Mean 3rd Qu. Max.
121 ## 4.300 5.100 5.800 5.843 6.400 7.900</code></pre>
122 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">fivenum</span>(iris<span class="op">$</span>Sepal.Length)</code></pre></div>
123 <pre><code>## [1] 4.3 5.1 5.8 6.4 7.9</code></pre>
124 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">summary</span>(iris<span class="op">$</span>Species)</code></pre></div>
125 <pre><code>## setosa versicolor virginica
126 ## 50 50 50</code></pre>
127 </div>
128 <div id="the-skim-function" class="section level2">
129 <h2>The <code>skim()</code> function</h2>
130 <p>The core function of <code>skimr</code> is <code>skim()</code>, which is designed to work with (grouped) data frames, and will try coerce other objects to data frames if possible. Like <code>summary()</code>, <code>skim()</code>’s method for data frames presents results for every column; the statistics it provides depend on the class of the variable.</p>
131 <div id="skimming-data-frames" class="section level3">
132 <h3>Skimming data frames</h3>
133 <p>By design, the main focus of <code>skimr</code> is on data frames; it is intended to fit well within a data <a href="http://r4ds.had.co.nz/pipes.html">pipeline</a> and relies extensively on <a href="https://tidyverse.org/">tidyverse</a> vocabulary, which focuses on data frames.</p>
134 <p>Results of <code>skim()</code> are <em>printed</em> horizontally, with one section per variable type and one row per variable.</p>
135 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(skimr)
136 <span class="kw">skim</span>(iris)</code></pre></div>
137 <pre><code>## ── Data Summary ────────────────────────
138 ## Values
139 ## Name iris
140 ## Number of rows 150
141 ## Number of columns 5
142 ## _______________________
143 ## Column type frequency:
144 ## factor 1
145 ## numeric 4
146 ## ________________________
147 ## Group variables None
148 ##
149 ## ── Variable type: factor ───────────────────────────────────────────────────────
150 ## skim_variable n_missing complete_rate ordered n_unique
151 ## 1 Species 0 1 FALSE 3
152 ## top_counts
153 ## 1 set: 50, ver: 50, vir: 50
154 ##
155 ## ── Variable type: numeric ──────────────────────────────────────────────────────
156 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
157 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
158 ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3
159 ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1
160 ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8
161 ## p100 hist
162 ## 1 7.9 ▆▇▇▅▂
163 ## 2 4.4 ▁▆▇▂▁
164 ## 3 6.9 ▇▁▆▇▂
165 ## 4 2.5 ▇▁▇▅▃</code></pre>
166 <p>The format of the results are a single wide data frame combining the results, with some additional attributes and two metadata columns:</p>
167 <ul>
168 <li><code>skim_variable</code>: name of the original variable</li>
169 <li><code>skim_type</code>: class of the variable</li>
170 </ul>
171 <p>Unlike many other objects within <code>R</code>, these columns are intrinsic to the <code>skim_df</code> class. Dropping these variables will result in a coercion to a <code>tibble</code>. The <code>is_skim_df()</code> function is used to assert that an object is a skim_df.</p>
172 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">is_skim_df</span>()</code></pre></div>
173 <pre><code>## [1] TRUE
174 ## attr(,&quot;message&quot;)
175 ## character(0)</code></pre>
176 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
177 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(<span class="op">-</span>skim_type, <span class="op">-</span>skim_variable) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">is_skim_df</span>()</code></pre></div>
178 <pre><code>## [1] FALSE
179 ## attr(,&quot;message&quot;)
180 ## [1] &quot;Object is not a `skim_df`: missing column `skim_type`; missing column `skim_variable`&quot;</code></pre>
181 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
182 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(<span class="op">-</span>n_missing) <span class="op">%&gt;%</span><span class="st"> </span><span class="kw">is_skim_df</span>()</code></pre></div>
183 <pre><code>## [1] TRUE
184 ## attr(,&quot;message&quot;)
185 ## character(0)</code></pre>
186 <p>In order to avoid type coercion, columns for summary statistics for different types are prefixed with the corresponding <code>skim_type</code>. This means that the columns of the <code>skim_df</code> are somewhat sparse, with quite a few missing values. This is because for some statistics the representations for different types of variables is different. For example, the mean of a Date variable and of a numeric variable are represented differently when printing, but this cannot be supported in a single vector. The exception to this are <code>n_missing</code> and <code>complete_rate</code> (missing/number of observations) which are the same for all types of variables.</p>
187 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
188 <span class="st"> </span>tibble<span class="op">::</span><span class="kw">as_tibble</span>()</code></pre></div>
189 <pre><code>## # A tibble: 5 x 15
190 ## skim_type skim_variable n_missing complete_rate factor.ordered factor.n_unique
191 ## &lt;chr&gt; &lt;chr&gt; &lt;int&gt; &lt;dbl&gt; &lt;lgl&gt; &lt;int&gt;
192 ## 1 factor Species 0 1 FALSE 3
193 ## 2 numeric Sepal.Length 0 1 NA NA
194 ## 3 numeric Sepal.Width 0 1 NA NA
195 ## 4 numeric Petal.Length 0 1 NA NA
196 ## 5 numeric Petal.Width 0 1 NA NA
197 ## # … with 9 more variables: factor.top_counts &lt;chr&gt;, numeric.mean &lt;dbl&gt;,
198 ## # numeric.sd &lt;dbl&gt;, numeric.p0 &lt;dbl&gt;, numeric.p25 &lt;dbl&gt;, numeric.p50 &lt;dbl&gt;,
199 ## # numeric.p75 &lt;dbl&gt;, numeric.p100 &lt;dbl&gt;, numeric.hist &lt;chr&gt;</code></pre>
200 <p>This is in contrast to <code>summary.data.frame()</code>, which stores statistics in a <code>table</code>. The distinction is important, because the <code>skim_df</code> object is pipeable and easy to use for additional manipulation: for example, the user could select all of the variable means, or all summary statistics for a specific variable.</p>
201 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
202 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">filter</span>(skim_variable <span class="op">==</span><span class="st"> &quot;Petal.Length&quot;</span>)</code></pre></div>
203 <pre><code>## ── Data Summary ────────────────────────
204 ## Values
205 ## Name iris
206 ## Number of rows 150
207 ## Number of columns 5
208 ## _______________________
209 ## Column type frequency:
210 ## numeric 1
211 ## ________________________
212 ## Group variables None
213 ##
214 ## ── Variable type: numeric ──────────────────────────────────────────────────────
215 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
216 ## 1 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1
217 ## p100 hist
218 ## 1 6.9 ▇▁▆▇▂</code></pre>
219 <p>Most <code>dplyr</code> verbs should work as expected.</p>
220 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
221 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(skim_type, skim_variable, n_missing)</code></pre></div>
222 <pre><code>## ── Data Summary ────────────────────────
223 ## Values
224 ## Name iris
225 ## Number of rows 150
226 ## Number of columns 5
227 ## _______________________
228 ## Column type frequency:
229 ## factor 1
230 ## numeric 4
231 ## ________________________
232 ## Group variables None
233 ##
234 ## ── Variable type: factor ───────────────────────────────────────────────────────
235 ## skim_variable n_missing
236 ## 1 Species 0
237 ##
238 ## ── Variable type: numeric ──────────────────────────────────────────────────────
239 ## skim_variable n_missing
240 ## 1 Sepal.Length 0
241 ## 2 Sepal.Width 0
242 ## 3 Petal.Length 0
243 ## 4 Petal.Width 0</code></pre>
244 <p>The base skimmers <code>n_missing</code> and <code>complete_rate</code> are computed for all of the columns in the data. But all other type-based skimmers have a namespace. You need to use a <code>skim_type</code> prefix to refer to correct column.</p>
245 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris) <span class="op">%&gt;%</span>
246 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">select</span>(skim_type, skim_variable, numeric.mean)</code></pre></div>
247 <pre><code>## ── Data Summary ────────────────────────
248 ## Values
249 ## Name iris
250 ## Number of rows 150
251 ## Number of columns 5
252 ## _______________________
253 ## Column type frequency:
254 ## factor 1
255 ## numeric 4
256 ## ________________________
257 ## Group variables None
258 ##
259 ## ── Variable type: factor ───────────────────────────────────────────────────────
260 ## skim_variable
261 ## 1 Species
262 ##
263 ## ── Variable type: numeric ──────────────────────────────────────────────────────
264 ## skim_variable mean
265 ## 1 Sepal.Length 5.84
266 ## 2 Sepal.Width 3.06
267 ## 3 Petal.Length 3.76
268 ## 4 Petal.Width 1.20</code></pre>
269 <p><code>skim()</code> also supports grouped data created by <code>dplyr::group_by()</code>. In this case, one additional column for each grouping variable is added to the <code>skim_df</code> object.</p>
270 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
271 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">group_by</span>(Species) <span class="op">%&gt;%</span>
272 <span class="st"> </span><span class="kw">skim</span>()</code></pre></div>
273 <pre><code>## ── Data Summary ────────────────────────
274 ## Values
275 ## Name Piped data
276 ## Number of rows 150
277 ## Number of columns 5
278 ## _______________________
279 ## Column type frequency:
280 ## numeric 4
281 ## ________________________
282 ## Group variables Species
283 ##
284 ## ── Variable type: numeric ──────────────────────────────────────────────────────
285 ## skim_variable Species n_missing complete_rate mean sd p0 p25
286 ## 1 Sepal.Length setosa 0 1 5.01 0.352 4.3 4.8
287 ## 2 Sepal.Length versicolor 0 1 5.94 0.516 4.9 5.6
288 ## 3 Sepal.Length virginica 0 1 6.59 0.636 4.9 6.22
289 ## 4 Sepal.Width setosa 0 1 3.43 0.379 2.3 3.2
290 ## 5 Sepal.Width versicolor 0 1 2.77 0.314 2 2.52
291 ## 6 Sepal.Width virginica 0 1 2.97 0.322 2.2 2.8
292 ## 7 Petal.Length setosa 0 1 1.46 0.174 1 1.4
293 ## 8 Petal.Length versicolor 0 1 4.26 0.470 3 4
294 ## 9 Petal.Length virginica 0 1 5.55 0.552 4.5 5.1
295 ## 10 Petal.Width setosa 0 1 0.246 0.105 0.1 0.2
296 ## 11 Petal.Width versicolor 0 1 1.33 0.198 1 1.2
297 ## 12 Petal.Width virginica 0 1 2.03 0.275 1.4 1.8
298 ## p50 p75 p100 hist
299 ## 1 5 5.2 5.8 ▃▃▇▅▁
300 ## 2 5.9 6.3 7 ▂▇▆▃▃
301 ## 3 6.5 6.9 7.9 ▁▃▇▃▂
302 ## 4 3.4 3.68 4.4 ▁▃▇▅▂
303 ## 5 2.8 3 3.4 ▁▅▆▇▂
304 ## 6 3 3.18 3.8 ▂▆▇▅▁
305 ## 7 1.5 1.58 1.9 ▁▃▇▃▁
306 ## 8 4.35 4.6 5.1 ▂▂▇▇▆
307 ## 9 5.55 5.88 6.9 ▃▇▇▃▂
308 ## 10 0.2 0.3 0.6 ▇▂▂▁▁
309 ## 11 1.3 1.5 1.8 ▅▇▃▆▁
310 ## 12 2 2.3 2.5 ▂▇▆▅▇</code></pre>
311 <p>Individual columns from a data frame may be selected using tidyverse-style selectors.</p>
312 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris, Sepal.Length, Species)</code></pre></div>
313 <pre><code>## ── Data Summary ────────────────────────
314 ## Values
315 ## Name iris
316 ## Number of rows 150
317 ## Number of columns 5
318 ## _______________________
319 ## Column type frequency:
320 ## factor 1
321 ## numeric 1
322 ## ________________________
323 ## Group variables None
324 ##
325 ## ── Variable type: factor ───────────────────────────────────────────────────────
326 ## skim_variable n_missing complete_rate ordered n_unique
327 ## 1 Species 0 1 FALSE 3
328 ## top_counts
329 ## 1 set: 50, ver: 50, vir: 50
330 ##
331 ## ── Variable type: numeric ──────────────────────────────────────────────────────
332 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
333 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
334 ## p100 hist
335 ## 1 7.9 ▆▇▇▅▂</code></pre>
336 <p>Or with common <code>select</code> helpers.</p>
337 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(iris, <span class="kw">starts_with</span>(<span class="st">&quot;Sepal&quot;</span>))</code></pre></div>
338 <pre><code>## ── Data Summary ────────────────────────
339 ## Values
340 ## Name iris
341 ## Number of rows 150
342 ## Number of columns 5
343 ## _______________________
344 ## Column type frequency:
345 ## numeric 2
346 ## ________________________
347 ## Group variables None
348 ##
349 ## ── Variable type: numeric ──────────────────────────────────────────────────────
350 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
351 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
352 ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3
353 ## p100 hist
354 ## 1 7.9 ▆▇▇▅▂
355 ## 2 4.4 ▁▆▇▂▁</code></pre>
356 <p>If an individual column is of an unsupported class, it is treated as a character variable with a warning.</p>
357 </div>
358 </div>
359 <div id="skimming-vectors" class="section level2">
360 <h2>Skimming vectors</h2>
361 <p>In <code>skimr</code> v2, <code>skim()</code> will attempt to coerce non-data frames (such as vectors and matrices) to data frames. In most cases with vectors, the object being evaluated should be equivalent to wrapping the object in <code>as.data.frame()</code>.</p>
362 <p>For example, the <code>lynx</code> data set is class <code>ts</code>.</p>
363 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(lynx)</code></pre></div>
364 <pre><code>## ── Data Summary ────────────────────────
365 ## Values
366 ## Name lynx
367 ## Number of rows 114
368 ## Number of columns 1
369 ## _______________________
370 ## Column type frequency:
371 ## ts 1
372 ## ________________________
373 ## Group variables None
374 ##
375 ## ── Variable type: ts ───────────────────────────────────────────────────────────
376 ## skim_variable n_missing complete_rate start end frequency deltat mean sd
377 ## 1 x 0 1 1821 1934 1 1 1538. 1586.
378 ## min max median line_graph
379 ## 1 39 6991 771 ⡈⢄⡠⢁⣀⠒⣀⠔</code></pre>
380 <p>Which is the same as coercing to a data frame.</p>
381 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">all.equal</span>(<span class="kw">skim</span>(lynx), <span class="kw">skim</span>(<span class="kw">as.data.frame</span>(lynx)))</code></pre></div>
382 <pre><code>## [1] &quot;Attributes: &lt; Component \&quot;df_name\&quot;: 1 string mismatch &gt;&quot;</code></pre>
383 </div>
384 <div id="skimming-matrices" class="section level2">
385 <h2>Skimming matrices</h2>
386 <p><code>skimr</code> does not support skimming matrices directly but coerces them to data frames. Columns in the matrix become variables. This behavior is similar to <code>summary.matrix()</code>). Three possible ways to handle matrices with <code>skim()</code> parallel the three variations of the mean function for matrices.</p>
387 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">m &lt;-<span class="st"> </span><span class="kw">matrix</span>(<span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">5</span>, <span class="dv">6</span>, <span class="dv">7</span>, <span class="dv">8</span>, <span class="dv">9</span>, <span class="dv">10</span>, <span class="dv">11</span>, <span class="dv">12</span>), <span class="dt">nrow =</span> <span class="dv">4</span>, <span class="dt">ncol =</span> <span class="dv">3</span>)
388 m</code></pre></div>
389 <pre><code>## [,1] [,2] [,3]
390 ## [1,] 1 5 9
391 ## [2,] 2 6 10
392 ## [3,] 3 7 11
393 ## [4,] 4 8 12</code></pre>
394 <p>Skimming the matrix produces similar results to <code>colMeans()</code>.</p>
395 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">colMeans</span>(m)</code></pre></div>
396 <pre><code>## [1] 2.5 6.5 10.5</code></pre>
397 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(m) <span class="co"># Similar to summary.matrix and colMeans()</span></code></pre></div>
398 <pre><code>## ── Data Summary ────────────────────────
399 ## Values
400 ## Name m
401 ## Number of rows 4
402 ## Number of columns 3
403 ## _______________________
404 ## Column type frequency:
405 ## numeric 3
406 ## ________________________
407 ## Group variables None
408 ##
409 ## ── Variable type: numeric ──────────────────────────────────────────────────────
410 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
411 ## 1 V1 0 1 2.5 1.29 1 1.75 2.5 3.25
412 ## 2 V2 0 1 6.5 1.29 5 5.75 6.5 7.25
413 ## 3 V3 0 1 10.5 1.29 9 9.75 10.5 11.2
414 ## p100 hist
415 ## 1 4 ▇▇▁▇▇
416 ## 2 8 ▇▇▁▇▇
417 ## 3 12 ▇▇▁▇▇</code></pre>
418 <p>Skimming the transpose of the matrix will give row-wise results.</p>
419 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">rowMeans</span>(m)</code></pre></div>
420 <pre><code>## [1] 5 6 7 8</code></pre>
421 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(<span class="kw">t</span>(m))</code></pre></div>
422 <pre><code>## ── Data Summary ────────────────────────
423 ## Values
424 ## Name t(m)
425 ## Number of rows 3
426 ## Number of columns 4
427 ## _______________________
428 ## Column type frequency:
429 ## numeric 4
430 ## ________________________
431 ## Group variables None
432 ##
433 ## ── Variable type: numeric ──────────────────────────────────────────────────────
434 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
435 ## 1 V1 0 1 5 4 1 3 5 7
436 ## 2 V2 0 1 6 4 2 4 6 8
437 ## 3 V3 0 1 7 4 3 5 7 9
438 ## 4 V4 0 1 8 4 4 6 8 10
439 ## p100 hist
440 ## 1 9 ▇▁▇▁▇
441 ## 2 10 ▇▁▇▁▇
442 ## 3 11 ▇▁▇▁▇
443 ## 4 12 ▇▁▇▁▇</code></pre>
444 <p>And call <code>c()</code> on the matrix to get results across all columns.</p>
445 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(<span class="kw">c</span>(m))</code></pre></div>
446 <pre><code>## ── Data Summary ────────────────────────
447 ## Values
448 ## Name c(m)
449 ## Number of rows 12
450 ## Number of columns 1
451 ## _______________________
452 ## Column type frequency:
453 ## numeric 1
454 ## ________________________
455 ## Group variables None
456 ##
457 ## ── Variable type: numeric ──────────────────────────────────────────────────────
458 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
459 ## 1 data 0 1 6.5 3.61 1 3.75 6.5 9.25
460 ## p100 hist
461 ## 1 12 ▇▅▅▅▇</code></pre>
462 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">mean</span>(m)</code></pre></div>
463 <pre><code>## [1] 6.5</code></pre>
464 <div id="skimming-without-modification" class="section level3">
465 <h3>Skimming without modification</h3>
466 <p><code>skim_tee()</code> produces the same printed version as <code>skim()</code> but returns the original, unmodified data frame. This allows for continued piping of the original data.</p>
467 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris_setosa &lt;-<span class="st"> </span>iris <span class="op">%&gt;%</span>
468 <span class="st"> </span><span class="kw">skim_tee</span>() <span class="op">%&gt;%</span>
469 <span class="st"> </span>dplyr<span class="op">::</span><span class="kw">filter</span>(Species <span class="op">==</span><span class="st"> &quot;setosa&quot;</span>)</code></pre></div>
470 <pre><code>## ── Data Summary ────────────────────────
471 ## Values
472 ## Name data
473 ## Number of rows 150
474 ## Number of columns 5
475 ## _______________________
476 ## Column type frequency:
477 ## factor 1
478 ## numeric 4
479 ## ________________________
480 ## Group variables None
481 ##
482 ## ── Variable type: factor ───────────────────────────────────────────────────────
483 ## skim_variable n_missing complete_rate ordered n_unique
484 ## 1 Species 0 1 FALSE 3
485 ## top_counts
486 ## 1 set: 50, ver: 50, vir: 50
487 ##
488 ## ── Variable type: numeric ──────────────────────────────────────────────────────
489 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
490 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
491 ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3
492 ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1
493 ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8
494 ## p100 hist
495 ## 1 7.9 ▆▇▇▅▂
496 ## 2 4.4 ▁▆▇▂▁
497 ## 3 6.9 ▇▁▆▇▂
498 ## 4 2.5 ▇▁▇▅▃</code></pre>
499 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">head</span>(iris_setosa)</code></pre></div>
500 <pre><code>## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
501 ## 1 5.1 3.5 1.4 0.2 setosa
502 ## 2 4.9 3.0 1.4 0.2 setosa
503 ## 3 4.7 3.2 1.3 0.2 setosa
504 ## 4 4.6 3.1 1.5 0.2 setosa
505 ## 5 5.0 3.6 1.4 0.2 setosa
506 ## 6 5.4 3.9 1.7 0.4 setosa</code></pre>
507 <p>Note, that <code>skim_tee()</code> is customized differently than <code>skim</code> itself. See below for more details.</p>
508 </div>
509 </div>
510 <div id="reshaping-the-results-from-skim" class="section level2">
511 <h2>Reshaping the results from <code>skim()</code></h2>
512 <p>As noted above, <code>skim()</code> returns a wide data frame. This is usually the most sensible format for the majority of operations when investigating data, but the package has some other functions to help with edge cases.</p>
513 <p>First, <code>partition()</code> returns a named list of the wide data frames for each data type. Unlike the original data the partitioned data only has columns corresponding to the skimming functions used for this data type. These data frames are, therefore, not <code>skim_df</code> objects.</p>
514 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
515 <span class="st"> </span><span class="kw">skim</span>() <span class="op">%&gt;%</span>
516 <span class="st"> </span><span class="kw">partition</span>()</code></pre></div>
517 <pre><code>## $factor
518 ##
519 ## ── Variable type: factor ───────────────────────────────────────────────────────
520 ## skim_variable n_missing complete_rate ordered n_unique
521 ## 1 Species 0 1 FALSE 3
522 ## top_counts
523 ## 1 set: 50, ver: 50, vir: 50
524 ##
525 ## $numeric
526 ##
527 ## ── Variable type: numeric ──────────────────────────────────────────────────────
528 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
529 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
530 ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3
531 ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1
532 ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8
533 ## p100 hist
534 ## 1 7.9 ▆▇▇▅▂
535 ## 2 4.4 ▁▆▇▂▁
536 ## 3 6.9 ▇▁▆▇▂
537 ## 4 2.5 ▇▁▇▅▃</code></pre>
538 <p>Alternatively, <code>yank()</code> selects only the subtable for a specific type. Think of it like <code>dplyr::select</code> on column types in the original data. Again, unsuitable columns are dropped.</p>
539 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
540 <span class="st"> </span><span class="kw">skim</span>() <span class="op">%&gt;%</span>
541 <span class="st"> </span><span class="kw">yank</span>(<span class="st">&quot;numeric&quot;</span>)</code></pre></div>
542 <pre><code>##
543 ## ── Variable type: numeric ──────────────────────────────────────────────────────
544 ## skim_variable n_missing complete_rate mean sd p0 p25 p50 p75
545 ## 1 Sepal.Length 0 1 5.84 0.828 4.3 5.1 5.8 6.4
546 ## 2 Sepal.Width 0 1 3.06 0.436 2 2.8 3 3.3
547 ## 3 Petal.Length 0 1 3.76 1.77 1 1.6 4.35 5.1
548 ## 4 Petal.Width 0 1 1.20 0.762 0.1 0.3 1.3 1.8
549 ## p100 hist
550 ## 1 7.9 ▆▇▇▅▂
551 ## 2 4.4 ▁▆▇▂▁
552 ## 3 6.9 ▇▁▆▇▂
553 ## 4 2.5 ▇▁▇▅▃</code></pre>
554 <p><code>to_long()</code> returns a single long data frame with columns <code>variable</code>, <code>type</code>, <code>statistic</code> and <code>formatted</code>. This is similar but not identical to the <code>skim_df</code> object in <code>skimr</code> v1.</p>
555 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
556 <span class="st"> </span><span class="kw">skim</span>() <span class="op">%&gt;%</span>
557 <span class="st"> </span><span class="kw">to_long</span>() <span class="op">%&gt;%</span><span class="st"> </span>
558 <span class="st"> </span><span class="kw">head</span>()</code></pre></div>
559 <pre><code>## # A tibble: 6 x 4
560 ## skim_type skim_variable stat formatted
561 ## &lt;chr&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt;
562 ## 1 factor Species n_missing 0
563 ## 2 numeric Sepal.Length n_missing 0
564 ## 3 numeric Sepal.Width n_missing 0
565 ## 4 numeric Petal.Length n_missing 0
566 ## 5 numeric Petal.Width n_missing 0
567 ## 6 factor Species complete_rate 1</code></pre>
568 <p>Since the <code>skim_variable</code> and <code>skim_type</code> columns are a core component of the <code>skim_df</code> class, it’s possible to get unwanted side effects when using <code>dplyr::select()</code>. Instead, use <code>focus()</code> to select columns of the skimmed results and keep them as a <code>skim_df</code>; it always keeps the metadata column.</p>
569 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">iris <span class="op">%&gt;%</span>
570 <span class="st"> </span><span class="kw">skim</span>() <span class="op">%&gt;%</span>
571 <span class="st"> </span><span class="kw">focus</span>(n_missing, numeric.mean)</code></pre></div>
572 <pre><code>## ── Data Summary ────────────────────────
573 ## Values
574 ## Name Piped data
575 ## Number of rows 150
576 ## Number of columns 5
577 ## _______________________
578 ## Column type frequency:
579 ## factor 1
580 ## numeric 4
581 ## ________________________
582 ## Group variables None
583 ##
584 ## ── Variable type: factor ───────────────────────────────────────────────────────
585 ## skim_variable n_missing
586 ## 1 Species 0
587 ##
588 ## ── Variable type: numeric ──────────────────────────────────────────────────────
589 ## skim_variable n_missing mean
590 ## 1 Sepal.Length 0 5.84
591 ## 2 Sepal.Width 0 3.06
592 ## 3 Petal.Length 0 3.76
593 ## 4 Petal.Width 0 1.20</code></pre>
594 </div>
595 <div id="rendering-the-results-of-skim" class="section level2">
596 <h2>Rendering the results of <code>skim()</code></h2>
597 <p>The <code>skim_df</code> object is a wide data frame. The display is created by default using <code>print.skim_df()</code>; users can specify additional options by explicitly calling <code>print([skim_df object], ...)</code>.</p>
598 <p>For documents rendered by <code>knitr</code>, the package provides a custom <code>knit_print</code> method. To use it, the final line of your code chunk should have a <code>skim_df</code> object.</p>
599 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(Orange)</code></pre></div>
600 <table>
601 <caption>Data summary</caption>
602 <tbody>
603 <tr class="odd">
604 <td align="left">Name</td>
605 <td align="left">Orange</td>
606 </tr>
607 <tr class="even">
608 <td align="left">Number of rows</td>
609 <td align="left">35</td>
610 </tr>
611 <tr class="odd">
612 <td align="left">Number of columns</td>
613 <td align="left">3</td>
614 </tr>
615 <tr class="even">
616 <td align="left">_______________________</td>
617 <td align="left"></td>
618 </tr>
619 <tr class="odd">
620 <td align="left">Column type frequency:</td>
621 <td align="left"></td>
622 </tr>
623 <tr class="even">
624 <td align="left">factor</td>
625 <td align="left">1</td>
626 </tr>
627 <tr class="odd">
628 <td align="left">numeric</td>
629 <td align="left">2</td>
630 </tr>
631 <tr class="even">
632 <td align="left">________________________</td>
633 <td align="left"></td>
634 </tr>
635 <tr class="odd">
636 <td align="left">Group variables</td>
637 <td align="left">None</td>
638 </tr>
639 </tbody>
640 </table>
641 <p><strong>Variable type: factor</strong></p>
642 <table>
643 <thead>
644 <tr class="header">
645 <th align="left">skim_variable</th>
646 <th align="right">n_missing</th>
647 <th align="right">complete_rate</th>
648 <th align="left">ordered</th>
649 <th align="right">n_unique</th>
650 <th align="left">top_counts</th>
651 </tr>
652 </thead>
653 <tbody>
654 <tr class="odd">
655 <td align="left">Tree</td>
656 <td align="right">0</td>
657 <td align="right">1</td>
658 <td align="left">TRUE</td>
659 <td align="right">5</td>
660 <td align="left">3: 7, 1: 7, 5: 7, 2: 7</td>
661 </tr>
662 </tbody>
663 </table>
664 <p><strong>Variable type: numeric</strong></p>
665 <table>
666 <thead>
667 <tr class="header">
668 <th align="left">skim_variable</th>
669 <th align="right">n_missing</th>
670 <th align="right">complete_rate</th>
671 <th align="right">mean</th>
672 <th align="right">sd</th>
673 <th align="right">p0</th>
674 <th align="right">p25</th>
675 <th align="right">p50</th>
676 <th align="right">p75</th>
677 <th align="right">p100</th>
678 <th align="left">hist</th>
679 </tr>
680 </thead>
681 <tbody>
682 <tr class="odd">
683 <td align="left">age</td>
684 <td align="right">0</td>
685 <td align="right">1</td>
686 <td align="right">922.14</td>
687 <td align="right">491.86</td>
688 <td align="right">118</td>
689 <td align="right">484.0</td>
690 <td align="right">1004</td>
691 <td align="right">1372.0</td>
692 <td align="right">1582</td>
693 <td align="left">▃▇▁▇▇</td>
694 </tr>
695 <tr class="even">
696 <td align="left">circumference</td>
697 <td align="right">0</td>
698 <td align="right">1</td>
699 <td align="right">115.86</td>
700 <td align="right">57.49</td>
701 <td align="right">30</td>
702 <td align="right">65.5</td>
703 <td align="right">115</td>
704 <td align="right">161.5</td>
705 <td align="right">214</td>
706 <td align="left">▇▃▇▇▅</td>
707 </tr>
708 </tbody>
709 </table>
710 <p>The same type of rendering is available from reshaped <code>skim_df</code> objects, those generated by <code>partition()</code> and <code>yank()</code> in particular.</p>
711 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">skim</span>(Orange) <span class="op">%&gt;%</span>
712 <span class="st"> </span><span class="kw">yank</span>(<span class="st">&quot;numeric&quot;</span>)</code></pre></div>
713 <p><strong>Variable type: numeric</strong></p>
714 <table>
715 <thead>
716 <tr class="header">
717 <th align="left">skim_variable</th>
718 <th align="right">n_missing</th>
719 <th align="right">complete_rate</th>
720 <th align="right">mean</th>
721 <th align="right">sd</th>
722 <th align="right">p0</th>
723 <th align="right">p25</th>
724 <th align="right">p50</th>
725 <th align="right">p75</th>
726 <th align="right">p100</th>
727 <th align="left">hist</th>
728 </tr>
729 </thead>
730 <tbody>
731 <tr class="odd">
732 <td align="left">age</td>
733 <td align="right">0</td>
734 <td align="right">1</td>
735 <td align="right">922.14</td>
736 <td align="right">491.86</td>
737 <td align="right">118</td>
738 <td align="right">484.0</td>
739 <td align="right">1004</td>
740 <td align="right">1372.0</td>
741 <td align="right">1582</td>
742 <td align="left">▃▇▁▇▇</td>
743 </tr>
744 <tr class="even">
745 <td align="left">circumference</td>
746 <td align="right">0</td>
747 <td align="right">1</td>
748 <td align="right">115.86</td>
749 <td align="right">57.49</td>
750 <td align="right">30</td>
751 <td align="right">65.5</td>
752 <td align="right">115</td>
753 <td align="right">161.5</td>
754 <td align="right">214</td>
755 <td align="left">▇▃▇▇▅</td>
756 </tr>
757 </tbody>
758 </table>
759 </div>
760 <div id="customizing-print-options" class="section level2">
761 <h2>Customizing print options</h2>
762 <p>Although its not a common use case outside of writing vignettes about <code>skimr</code>, you can fall back to default printing methods by adding the chunk option <code>render = knitr::normal_print</code>.</p>
763 <p>You can also disable the <code>skimr</code> summary by setting the chunk option <code>skimr_include_summary = FALSE</code>.</p>
764 <p>You can change the number of digits shown in the columns of generated statistics by changing the <code>skimr_digits</code> chunk option.</p>
765 </div>
766 <div id="modifying-skim" class="section level2">
767 <h2>Modifying <code>skim()</code></h2>
768 <p><code>skimr</code> is opinionated in its choice of defaults, but users can easily add, replace, or remove the statistics for a class. For interactive use, you can create your own skimming function with the <code>skim_with()</code> factory. <code>skimr</code> also has an API for extensions in other packages. Working with that is covered later.</p>
769 <p>To add a statistic for a data type, create an <code>sfl()</code> (a <code>skimr</code> function list) for each class that you want to change:</p>
770 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">my_skim &lt;-<span class="st"> </span><span class="kw">skim_with</span>(<span class="dt">numeric =</span> <span class="kw">sfl</span>(<span class="dt">new_mad =</span> mad))
771 <span class="kw">my_skim</span>(faithful)</code></pre></div>
772 <table>
773 <caption>Data summary</caption>
774 <tbody>
775 <tr class="odd">
776 <td align="left">Name</td>
777 <td align="left">faithful</td>
778 </tr>
779 <tr class="even">
780 <td align="left">Number of rows</td>
781 <td align="left">272</td>
782 </tr>
783 <tr class="odd">
784 <td align="left">Number of columns</td>
785 <td align="left">2</td>
786 </tr>
787 <tr class="even">
788 <td align="left">_______________________</td>
789 <td align="left"></td>
790 </tr>
791 <tr class="odd">
792 <td align="left">Column type frequency:</td>
793 <td align="left"></td>
794 </tr>
795 <tr class="even">
796 <td align="left">numeric</td>
797 <td align="left">2</td>
798 </tr>
799 <tr class="odd">
800 <td align="left">________________________</td>
801 <td align="left"></td>
802 </tr>
803 <tr class="even">
804 <td align="left">Group variables</td>
805 <td align="left">None</td>
806 </tr>
807 </tbody>
808 </table>
809 <p><strong>Variable type: numeric</strong></p>
810 <table>
811 <thead>
812 <tr class="header">
813 <th align="left">skim_variable</th>
814 <th align="right">n_missing</th>
815 <th align="right">complete_rate</th>
816 <th align="right">mean</th>
817 <th align="right">sd</th>
818 <th align="right">p0</th>
819 <th align="right">p25</th>
820 <th align="right">p50</th>
821 <th align="right">p75</th>
822 <th align="right">p100</th>
823 <th align="left">hist</th>
824 <th align="right">new_mad</th>
825 </tr>
826 </thead>
827 <tbody>
828 <tr class="odd">
829 <td align="left">eruptions</td>
830 <td align="right">0</td>
831 <td align="right">1</td>
832 <td align="right">3.49</td>
833 <td align="right">1.14</td>
834 <td align="right">1.6</td>
835 <td align="right">2.16</td>
836 <td align="right">4</td>
837 <td align="right">4.45</td>
838 <td align="right">5.1</td>
839 <td align="left">▇▂▂▇▇</td>
840 <td align="right">0.95</td>
841 </tr>
842 <tr class="even">
843 <td align="left">waiting</td>
844 <td align="right">0</td>
845 <td align="right">1</td>
846 <td align="right">70.90</td>
847 <td align="right">13.59</td>
848 <td align="right">43.0</td>
849 <td align="right">58.00</td>
850 <td align="right">76</td>
851 <td align="right">82.00</td>
852 <td align="right">96.0</td>
853 <td align="left">▃▃▂▇▂</td>
854 <td align="right">11.86</td>
855 </tr>
856 </tbody>
857 </table>
858 <p>As the previous example suggests, the default is to append <em>new</em> summary statistics to the preexisting set. This behavior isn’t always desirable, especially when you want lots of changes. To stop appending, set <code>append = FALSE</code>.</p>
859 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">my_skim &lt;-<span class="st"> </span><span class="kw">skim_with</span>(<span class="dt">numeric =</span> <span class="kw">sfl</span>(<span class="dt">new_mad =</span> mad), <span class="dt">append =</span> <span class="ot">FALSE</span>)
860 <span class="kw">my_skim</span>(faithful)</code></pre></div>
861 <table>
862 <caption>Data summary</caption>
863 <tbody>
864 <tr class="odd">
865 <td align="left">Name</td>
866 <td align="left">faithful</td>
867 </tr>
868 <tr class="even">
869 <td align="left">Number of rows</td>
870 <td align="left">272</td>
871 </tr>
872 <tr class="odd">
873 <td align="left">Number of columns</td>
874 <td align="left">2</td>
875 </tr>
876 <tr class="even">
877 <td align="left">_______________________</td>
878 <td align="left"></td>
879 </tr>
880 <tr class="odd">
881 <td align="left">Column type frequency:</td>
882 <td align="left"></td>
883 </tr>
884 <tr class="even">
885 <td align="left">numeric</td>
886 <td align="left">2</td>
887 </tr>
888 <tr class="odd">
889 <td align="left">________________________</td>
890 <td align="left"></td>
891 </tr>
892 <tr class="even">
893 <td align="left">Group variables</td>
894 <td align="left">None</td>
895 </tr>
896 </tbody>
897 </table>
898 <p><strong>Variable type: numeric</strong></p>
899 <table>
900 <thead>
901 <tr class="header">
902 <th align="left">skim_variable</th>
903 <th align="right">n_missing</th>
904 <th align="right">complete_rate</th>
905 <th align="right">new_mad</th>
906 </tr>
907 </thead>
908 <tbody>
909 <tr class="odd">
910 <td align="left">eruptions</td>
911 <td align="right">0</td>
912 <td align="right">1</td>
913 <td align="right">0.95</td>
914 </tr>
915 <tr class="even">
916 <td align="left">waiting</td>
917 <td align="right">0</td>
918 <td align="right">1</td>
919 <td align="right">11.86</td>
920 </tr>
921 </tbody>
922 </table>
923 <p>You can also use <code>skim_with()</code> to remove specific statistics by setting them to <code>NULL</code>. This is commonly used to disable the inline histograms and spark graphs.</p>
924 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">no_hist &lt;-<span class="st"> </span><span class="kw">skim_with</span>(<span class="dt">ts =</span> <span class="kw">sfl</span>(<span class="dt">line_graph =</span> <span class="ot">NULL</span>))
925 <span class="kw">no_hist</span>(Nile)</code></pre></div>
926 <table>
927 <caption>Data summary</caption>
928 <tbody>
929 <tr class="odd">
930 <td align="left">Name</td>
931 <td align="left">Nile</td>
932 </tr>
933 <tr class="even">
934 <td align="left">Number of rows</td>
935 <td align="left">100</td>
936 </tr>
937 <tr class="odd">
938 <td align="left">Number of columns</td>
939 <td align="left">1</td>
940 </tr>
941 <tr class="even">
942 <td align="left">_______________________</td>
943 <td align="left"></td>
944 </tr>
945 <tr class="odd">
946 <td align="left">Column type frequency:</td>
947 <td align="left"></td>
948 </tr>
949 <tr class="even">
950 <td align="left">ts</td>
951 <td align="left">1</td>
952 </tr>
953 <tr class="odd">
954 <td align="left">________________________</td>
955 <td align="left"></td>
956 </tr>
957 <tr class="even">
958 <td align="left">Group variables</td>
959 <td align="left">None</td>
960 </tr>
961 </tbody>
962 </table>
963 <p><strong>Variable type: ts</strong></p>
964 <table>
965 <thead>
966 <tr class="header">
967 <th align="left">skim_variable</th>
968 <th align="right">n_missing</th>
969 <th align="right">complete_rate</th>
970 <th align="right">start</th>
971 <th align="right">end</th>
972 <th align="right">frequency</th>
973 <th align="right">deltat</th>
974 <th align="right">mean</th>
975 <th align="right">sd</th>
976 <th align="right">min</th>
977 <th align="right">max</th>
978 <th align="right">median</th>
979 </tr>
980 </thead>
981 <tbody>
982 <tr class="odd">
983 <td align="left">x</td>
984 <td align="right">0</td>
985 <td align="right">1</td>
986 <td align="right">1871</td>
987 <td align="right">1970</td>
988 <td align="right">1</td>
989 <td align="right">1</td>
990 <td align="right">919.35</td>
991 <td align="right">169.23</td>
992 <td align="right">456</td>
993 <td align="right">1370</td>
994 <td align="right">893.5</td>
995 </tr>
996 </tbody>
997 </table>
998 <p>The same pattern applies to changing skimmers for multiple classes simultaneously. If you want to partially-apply function arguments, use the Tidyverse lambda syntax.</p>
999 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">my_skim &lt;-<span class="st"> </span><span class="kw">skim_with</span>(
1000 <span class="dt">numeric =</span> <span class="kw">sfl</span>(<span class="dt">total =</span> <span class="op">~</span><span class="st"> </span><span class="kw">sum</span>(., <span class="dt">na.rm =</span> <span class="ot">TRUE</span>)),
1001 <span class="dt">factor =</span> <span class="kw">sfl</span>(<span class="dt">missing =</span> <span class="op">~</span><span class="st"> </span><span class="kw">sum</span>(<span class="kw">is.na</span>(.))),
1002 <span class="dt">append =</span> <span class="ot">FALSE</span>
1003 )
1004
1005 <span class="kw">my_skim</span>(iris)</code></pre></div>
1006 <table>
1007 <caption>Data summary</caption>
1008 <tbody>
1009 <tr class="odd">
1010 <td align="left">Name</td>
1011 <td align="left">iris</td>
1012 </tr>
1013 <tr class="even">
1014 <td align="left">Number of rows</td>
1015 <td align="left">150</td>
1016 </tr>
1017 <tr class="odd">
1018 <td align="left">Number of columns</td>
1019 <td align="left">5</td>
1020 </tr>
1021 <tr class="even">
1022 <td align="left">_______________________</td>
1023 <td align="left"></td>
1024 </tr>
1025 <tr class="odd">
1026 <td align="left">Column type frequency:</td>
1027 <td align="left"></td>
1028 </tr>
1029 <tr class="even">
1030 <td align="left">factor</td>
1031 <td align="left">1</td>
1032 </tr>
1033 <tr class="odd">
1034 <td align="left">numeric</td>
1035 <td align="left">4</td>
1036 </tr>
1037 <tr class="even">
1038 <td align="left">________________________</td>
1039 <td align="left"></td>
1040 </tr>
1041 <tr class="odd">
1042 <td align="left">Group variables</td>
1043 <td align="left">None</td>
1044 </tr>
1045 </tbody>
1046 </table>
1047 <p><strong>Variable type: factor</strong></p>
1048 <table>
1049 <thead>
1050 <tr class="header">
1051 <th align="left">skim_variable</th>
1052 <th align="right">n_missing</th>
1053 <th align="right">complete_rate</th>
1054 <th align="right">missing</th>
1055 </tr>
1056 </thead>
1057 <tbody>
1058 <tr class="odd">
1059 <td align="left">Species</td>
1060 <td align="right">0</td>
1061 <td align="right">1</td>
1062 <td align="right">0</td>
1063 </tr>
1064 </tbody>
1065 </table>
1066 <p><strong>Variable type: numeric</strong></p>
1067 <table>
1068 <thead>
1069 <tr class="header">
1070 <th align="left">skim_variable</th>
1071 <th align="right">n_missing</th>
1072 <th align="right">complete_rate</th>
1073 <th align="right">total</th>
1074 </tr>
1075 </thead>
1076 <tbody>
1077 <tr class="odd">
1078 <td align="left">Sepal.Length</td>
1079 <td align="right">0</td>
1080 <td align="right">1</td>
1081 <td align="right">876.5</td>
1082 </tr>
1083 <tr class="even">
1084 <td align="left">Sepal.Width</td>
1085 <td align="right">0</td>
1086 <td align="right">1</td>
1087 <td align="right">458.6</td>
1088 </tr>
1089 <tr class="odd">
1090 <td align="left">Petal.Length</td>
1091 <td align="right">0</td>
1092 <td align="right">1</td>
1093 <td align="right">563.7</td>
1094 </tr>
1095 <tr class="even">
1096 <td align="left">Petal.Width</td>
1097 <td align="right">0</td>
1098 <td align="right">1</td>
1099 <td align="right">179.9</td>
1100 </tr>
1101 </tbody>
1102 </table>
1103 <p>To modify the “base” skimmers, refer to them in a similar manner. Since base skimmers are usually a small group, they must return the same type for all data types in R, <code>append</code> doesn’t apply here.</p>
1104 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">my_skim &lt;-<span class="st"> </span><span class="kw">skim_with</span>(<span class="dt">base =</span> <span class="kw">sfl</span>(<span class="dt">length =</span> length))
1105 <span class="kw">my_skim</span>(faithful)</code></pre></div>
1106 <table>
1107 <caption>Data summary</caption>
1108 <tbody>
1109 <tr class="odd">
1110 <td align="left">Name</td>
1111 <td align="left">faithful</td>
1112 </tr>
1113 <tr class="even">
1114 <td align="left">Number of rows</td>
1115 <td align="left">272</td>
1116 </tr>
1117 <tr class="odd">
1118 <td align="left">Number of columns</td>
1119 <td align="left">2</td>
1120 </tr>
1121 <tr class="even">
1122 <td align="left">_______________________</td>
1123 <td align="left"></td>
1124 </tr>
1125 <tr class="odd">
1126 <td align="left">Column type frequency:</td>
1127 <td align="left"></td>
1128 </tr>
1129 <tr class="even">
1130 <td align="left">numeric</td>
1131 <td align="left">2</td>
1132 </tr>
1133 <tr class="odd">
1134 <td align="left">________________________</td>
1135 <td align="left"></td>
1136 </tr>
1137 <tr class="even">
1138 <td align="left">Group variables</td>
1139 <td align="left">None</td>
1140 </tr>
1141 </tbody>
1142 </table>
1143 <p><strong>Variable type: numeric</strong></p>
1144 <table>
1145 <thead>
1146 <tr class="header">
1147 <th align="left">skim_variable</th>
1148 <th align="right">length</th>
1149 <th align="right">mean</th>
1150 <th align="right">sd</th>
1151 <th align="right">p0</th>
1152 <th align="right">p25</th>
1153 <th align="right">p50</th>
1154 <th align="right">p75</th>
1155 <th align="right">p100</th>
1156 <th align="left">hist</th>
1157 </tr>
1158 </thead>
1159 <tbody>
1160 <tr class="odd">
1161 <td align="left">eruptions</td>
1162 <td align="right">272</td>
1163 <td align="right">3.49</td>
1164 <td align="right">1.14</td>
1165 <td align="right">1.6</td>
1166 <td align="right">2.16</td>
1167 <td align="right">4</td>
1168 <td align="right">4.45</td>
1169 <td align="right">5.1</td>
1170 <td align="left">▇▂▂▇▇</td>
1171 </tr>
1172 <tr class="even">
1173 <td align="left">waiting</td>
1174 <td align="right">272</td>
1175 <td align="right">70.90</td>
1176 <td align="right">13.59</td>
1177 <td align="right">43.0</td>
1178 <td align="right">58.00</td>
1179 <td align="right">76</td>
1180 <td align="right">82.00</td>
1181 <td align="right">96.0</td>
1182 <td align="left">▃▃▂▇▂</td>
1183 </tr>
1184 </tbody>
1185 </table>
1186 </div>
1187 <div id="extending-skimr" class="section level2">
1188 <h2>Extending <code>skimr</code></h2>
1189 <p>Packages may wish to export their own <code>skim()</code> functions. Use <code>skim_with()</code> for this. In fact, this is how <code>skimr</code> generates its version of <code>skim()</code>.</p>
1190 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#' @export</span>
1191 my_package_skim &lt;-<span class="st"> </span><span class="kw">skim_with</span>()</code></pre></div>
1192 <p>Alternatively, defaults for another data types can be added to <code>skimr</code> with the <code>get_skimmers</code> generic. The method for your data type should return an <code>sfl()</code>. Unlike the <code>sfl()</code> used interactively, you also need to set the <code>skim_type</code> argument. It should match the method type in the function signature.</p>
1193 <div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">get_skimmers.my_type &lt;-<span class="st"> </span><span class="cf">function</span>(column) {
1194 <span class="kw">sfl</span>(
1195 <span class="dt">skim_type =</span> <span class="st">&quot;my_type&quot;</span>,
1196 <span class="dt">total =</span> sum
1197 )
1198 }
1199
1200 my_data &lt;-<span class="st"> </span><span class="kw">data.frame</span>(
1201 <span class="dt">my_type =</span> <span class="kw">structure</span>(<span class="dv">1</span><span class="op">:</span><span class="dv">3</span>, <span class="dt">class =</span> <span class="kw">c</span>(<span class="st">&quot;my_type&quot;</span>, <span class="st">&quot;integer&quot;</span>))
1202 )
1203 <span class="kw">skim</span>(my_data)</code></pre></div>
1204 <table>
1205 <caption>Data summary</caption>
1206 <tbody>
1207 <tr class="odd">
1208 <td align="left">Name</td>
1209 <td align="left">my_data</td>
1210 </tr>
1211 <tr class="even">
1212 <td align="left">Number of rows</td>
1213 <td align="left">3</td>
1214 </tr>
1215 <tr class="odd">
1216 <td align="left">Number of columns</td>
1217 <td align="left">1</td>
1218 </tr>
1219 <tr class="even">
1220 <td align="left">_______________________</td>
1221 <td align="left"></td>
1222 </tr>
1223 <tr class="odd">
1224 <td align="left">Column type frequency:</td>
1225 <td align="left"></td>
1226 </tr>
1227 <tr class="even">
1228 <td align="left">my_type</td>
1229 <td align="left">1</td>
1230 </tr>
1231 <tr class="odd">
1232 <td align="left">________________________</td>
1233 <td align="left"></td>
1234 </tr>
1235 <tr class="even">
1236 <td align="left">Group variables</td>
1237 <td align="left">None</td>
1238 </tr>
1239 </tbody>
1240 </table>
1241 <p><strong>Variable type: my_type</strong></p>
1242 <table>
1243 <thead>
1244 <tr class="header">
1245 <th align="left">skim_variable</th>
1246 <th align="right">n_missing</th>
1247 <th align="right">complete_rate</th>
1248 <th align="right">total</th>
1249 </tr>
1250 </thead>
1251 <tbody>
1252 <tr class="odd">
1253 <td align="left">my_type</td>
1254 <td align="right">0</td>
1255 <td align="right">1</td>
1256 <td align="right">6</td>
1257 </tr>
1258 </tbody>
1259 </table>
1260 <p>An extended example is available in the vignette <em>Supporting additional objects</em>.</p>
1261 </div>
1262 <div id="solutions-to-common-rendering-problems" class="section level2">
1263 <h2>Solutions to common rendering problems</h2>
1264 <p>The details of rendering are dependent on the operating system R is running on, the locale of the installation, and the fonts installed. Rendering may also differ based on whether it occurs in the console or when knitting to specific types of documents such as HTML and PDF.</p>
1265 <p>The most commonly reported problems involve rendering the spark graphs (inline histogram and line chart) on Windows. One common fix is to switch your locale. The function <code>fix_windows_histograms()</code> does this for you.</p>
1266 <p>In order to render the sparkgraphs in html or PDF histogram you may need to change fonts to one that supports blocks or Braille (depending on which you need). Please review the separate vignette and associated template for details.</p>
1267 </div>
1268
1269
1270
1271 <!-- code folding -->
1272
1273
1274 <!-- dynamically load mathjax for compatibility with self-contained -->
1275 <script>
1276 (function () {
1277 var script = document.createElement("script");
1278 script.type = "text/javascript";
1279 script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
1280 document.getElementsByTagName("head")[0].appendChild(script);
1281 })();
1282 </script>
1283
1284 </body>
1285 </html>