generated from intro-to-data-science-22-workshop/00-template-munzert-kermit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
janitor-exercises.html
564 lines (480 loc) · 21.7 KB
/
janitor-exercises.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<meta name="author" content="Abigail Peña Alejos & Nikolina Klatt" />
<meta name="date" content="2022-11-13" />
<title>Janitor exercises</title>
<script src="janitor-exercises_files/header-attrs-2.17/header-attrs.js"></script>
<script src="janitor-exercises_files/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="janitor-exercises_files/bootstrap-3.3.5/css/lumen.min.css" rel="stylesheet" />
<script src="janitor-exercises_files/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="janitor-exercises_files/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="janitor-exercises_files/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="janitor-exercises_files/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="janitor-exercises_files/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="janitor-exercises_files/tocify-1.9.1/jquery.tocify.js"></script>
<script src="janitor-exercises_files/navigation-1.1/tabsets.js"></script>
<link href="janitor-exercises_files/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
<script src="janitor-exercises_files/pagedtable-1.1/js/pagedtable.js"></script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">
code {
white-space: pre;
}
.sourceCode {
overflow: visible;
}
</style>
<style type="text/css" data-origin="pandoc">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ background-color: #f8f8f8; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script>
// apply pandoc div.sourceCode style to pre.sourceCode instead
(function() {
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
var j = 0;
while (j < rules.length) {
var rule = rules[j];
// check if there is a div.sourceCode rule
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") {
j++;
continue;
}
var style = rule.style.cssText;
// check if color or background-color is set
if (rule.style.color === '' && rule.style.backgroundColor === '') {
j++;
continue;
}
// replace div.sourceCode by a pre.sourceCode rule
sheets[i].deleteRule(j);
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
}
}
})();
</script>
<link rel="stylesheet" href="custom.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div id="header">
<h1 class="title toc-ignore">Janitor exercises</h1>
<h4 class="author">Abigail Peña Alejos & Nikolina Klatt</h4>
<h4 class="date">2022-11-13</h4>
</div>
<p>Today we will check some of the basic functions offered by the
<code>janitor package</code> that will help us save time when cleaning
our data. Along with <code>janitor</code>, we will make use of
<code>tidyverse</code>packages such as <code>dplyr</code> and
<code>readr</code>. <code>kableExtra</code> is suggested to render nice
tables. But it is up to you!</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(readr)</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(janitor)</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(kableExtra)</span></code></pre></div>
<p>For this exercise we will use <em>crime_subset.csv</em> dataset taken
from a real world data hosted at <a
href="https://catalog.data.gov/dataset">Data.gov catalogue</a>, the U.S.
Government’s open data portal. The dataset contains reported crimes in
the Montgomery County in Maryland. (You can download the original <a
href="https://catalog.data.gov/dataset/crime">here</a>)</p>
<p>We import the .csv file</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>crime_df <span class="ot"><-</span> <span class="fu">read_delim</span>(<span class="st">"data/crime_subset.csv"</span>, </span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> <span class="at">delim =</span> <span class="st">";"</span>, <span class="at">escape_double =</span> <span class="cn">FALSE</span>, <span class="at">trim_ws =</span> <span class="cn">TRUE</span>)</span></code></pre></div>
<p>Now, let’s go!</p>
<hr />
<div id="getting-our-variables-names-in-clean-format-with-clean_names"
class="section level2">
<h2>Getting our variables names in clean format with
<code>clean_names()</code></h2>
<p>We have talked in our presentation about naming convention in
computing, for example for variable and subroutine names, and for file
names. We have been recommended using <code>snake_case</code>, the style
of writing in which each whitespace is replaced by an underscore
<code>_</code> character, and each word is written in lowercase.
Something like this: <code>my_awesome_df</code>.</p>
<p>However, this isn’t the case for our dataset.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>crime_df <span class="sc">%>%</span> </span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">glimpse</span>()</span></code></pre></div>
<pre><code>## Rows: 102
## Columns: 12
## $ `Incident ID` <dbl> 201089454, 201201369, 201289022, 201396271, 201…
## $ `Offence Code` <dbl> 5404, 1399, 9113, 2305, 9108, 2902, 9199, 2399,…
## $ `CR Number` <dbl> 16035988, 180039918, 200020566, 220044986, 1705…
## $ `Dispatch/Date` <chr> NA, NA, "05/23/2020", "10/14/2022", NA, "03/21/…
## $ Time <chr> NA, NA, "11:19:55 AM", "07:03:06 AM", NA, "11:3…
## $ `NIBRS Code` <chr> "90D", "13B", "90Z", "23F", "90Z", "290", "90Z"…
## $ Latitud <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
## $ Victims <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ `Crime Name1` <chr> "Crime Against Society", "Crime Against Person"…
## $ `Crime Name2` <chr> "Driving Under the Influence", "Simple Assault"…
## $ `Police District Name` <chr> "SILVER SPRING", "SILVER SPRING", "SILVER SPRIN…
## $ ...12 <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…</code></pre>
<p><strong>EXERCISE 1:</strong> Change variable names of the dataframe
to follow <code>snake_case</code> convention.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
<p>Voilá! Now we have <code>snake_case</code> formatted variables! Btw,
did you notice the function also took care of the <code>/</code> in
<code>Dispatch/Date</code> and replaced it with an underscore. Isn’t it
great?</p>
<p>Let’s pretend you are not really fond of <code>snake_case</code>
format because you prefer the <code>camelCase</code>convention instead.
You might also want to leave NIBRS and ID untouched. No problem!
<code>clean_names()</code> got your back. Just change your preference in
the argument <code>case =</code> to <code>upper_camel</code> and keep
the abbreviation with the argument <code>abbreviations</code>. Check out
<code>?clean_names()</code> for further information.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
</div>
<div id="detect-duplicates-with-get_dupes" class="section level2">
<h2>Detect duplicates with <code>get_dupes()</code></h2>
<p><strong>EXERCISE 2:</strong> Find out whether there are any duplicate
values in the <em>crime_df</em> dataframe</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
<p>Uhlala, looks like our data needs some cleaning!</p>
</div>
<div id="remove-content-with-remove_empty-and-remove_constant-functions"
class="section level2">
<h2>Remove content with <code>remove_empty()</code> and
<code>remove_constant()</code> functions</h2>
<p>Our <code>crime_df</code> data contain several missing values, and a
couple of rows/columns filled with NAs.</p>
<p><strong>EXERCISE 3.1:</strong> Create a subset called
<em>tidy_crime</em> using the <code>remove_empty()</code></p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
<p><strong>EXERCISE 3.2:</strong> From <em>crime_df</em>, subset the
observation for crimes committed in <em>Silver Spring district</em>,
clean the data and get rid of the <em>police_distric_name</em>
variable.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
</div>
<div id="check-content-of-columns-with-compare_df_colums"
class="section level2">
<h2>Check content of columns with <code>compare_df_colums</code></h2>
<p><code>compare_df_colums</code> is a pretty cool function to check how
a group of dataset compare to each other and whether could be possible
to merge them based on the number of variables and vector class.</p>
<p><strong>Exercise 4</strong> From <em>crime_df</em>, subset the
observation for crimes committed in <em>Wheaton district</em> , clean
the data and get rid of the <em>police_distric_name</em> variable. Then
compare <em>Wheaton</em> and <em>Silver Spring</em> subsets. Check out
what columns are missing or present in the different inputs.</p>
</div>
<div id="using-tabyl-and-adorn_-options" class="section level2">
<h2>Using <code>tabyl()</code> and <code>adorn_*()</code> options</h2>
<p>We know that <code>tabyl()</code>is useful to create contingency
tables with 1, 2 or 3 variables, and we have learned that
<code>adorn_*()</code> functions will help us add information such as
total numbers, not to forget a nice formatting for percentages.</p>
<p><strong>EXERCISE 5.1:</strong> Find out proportion of crime per
district, round percentages to 1 digit.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
<p><strong>EXERCISE 5.2:</strong> For crimes committed in Silver Springs
involving only one victim, find what percentage corresponds to
property-related offences. DON’T USE <code>drop_na()</code></p>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
</div>
<div id="finally-lets-play-with-numbers-dates" class="section level2">
<h2>Finally, let’s play with numbers & dates</h2>
<p><strong>Rounding up numbers with
<code>round_half_up</code></strong></p>
<p>Following the example of <em>v1</em> vector, create 2 vectors in
which the numbers from vector 1 are rounded up to 1 and 0 digits
respectively. Bind the vectors into a tibble under the name
<code>funny_numbers</code> to see how the numbers compare across
columns</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>v1 <span class="ot"><-</span> <span class="fu">runif</span>(<span class="dv">10</span>, <span class="at">min=</span><span class="dv">15</span>, <span class="at">max=</span><span class="dv">48</span>)</span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
<p><strong>Playing with dates</strong></p>
<p>Use the <code>excel_numeric_to_date()</code> function to convert
Excel serial date numbers included in <em>edates</em> to class
<code>Date</code></p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>edates <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">0</span>, <span class="dv">59</span>, <span class="dv">61</span>, <span class="dv">1000</span>, <span class="dv">45100</span>)</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="co"># insert your code here</span></span></code></pre></div>
</div>
<div id="sources" class="section level2">
<h2>Sources</h2>
<p><a
href="https://cran.r-project.org/web/packages/janitor/janitor.pdf">janitor
package</a></p>
<p><a
href="https://cran.r-project.org/web/packages/janitor/vignettes/janitor.html#tabyl---a-better-version-of-table">overview
of janitor functions</a></p>
<p><a
href="http://jenrichmond.rbind.io/post/digging-into-the-janitor-package/">cleaning
penguins with the janitor packages</a></p>
<p><a
href="https://www.exploringdata.org/post/how-to-clean-data-janitor-package/">How
to Clean Data: {janitor} Package</a></p>
</div>
</div>
</div>
</div>
<script>
// add bootstrap table styles to pandoc tables
function bootstrapStylePandocTables() {
$('tr.odd').parent('tbody').parent('table').addClass('table table-condensed');
}
$(document).ready(function () {
bootstrapStylePandocTables();
});
</script>
<!-- tabsets -->
<script>
$(document).ready(function () {
window.buildTabsets("TOC");
});
$(document).ready(function () {
$('.tabset-dropdown > .nav-tabs > li').click(function () {
$(this).parent().toggleClass('nav-tabs-open');
});
});
</script>
<!-- code folding -->
<script>
$(document).ready(function () {
// temporarily add toc-ignore selector to headers for the consistency with Pandoc
$('.unlisted.unnumbered').addClass('toc-ignore')
// move toc-ignore selectors from section div to header
$('div.section.toc-ignore')
.removeClass('toc-ignore')
.children('h1,h2,h3,h4,h5').addClass('toc-ignore');
// establish options
var options = {
selectors: "h1,h2,h3",
theme: "bootstrap3",
context: '.toc-content',
hashGenerator: function (text) {
return text.replace(/[.\\/?&!#<>]/g, '').replace(/\s/g, '_');
},
ignoreSelector: ".toc-ignore",
scrollTo: 0
};
options.showAndHide = true;
options.smoothScroll = true;
// tocify
var toc = $("#TOC").tocify(options).data("toc-tocify");
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>
</html>