forked from tidyverse/datascience-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
u2-d08-multi-df.html
967 lines (766 loc) · 21.9 KB
/
u2-d08-multi-df.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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<title>Working with multiple data frames</title>
<meta charset="utf-8" />
<meta name="author" content="" />
<script src="libs/header-attrs/header-attrs.js"></script>
<link href="libs/font-awesome/css/all.css" rel="stylesheet" />
<link href="libs/font-awesome/css/v4-shims.css" rel="stylesheet" />
<link href="libs/panelset/panelset.css" rel="stylesheet" />
<script src="libs/panelset/panelset.js"></script>
<link rel="stylesheet" href="../xaringan-themer.css" type="text/css" />
<link rel="stylesheet" href="../slides.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: center, middle, inverse, title-slide
# Working with multiple data frames
## <br><br> College of the Atlantic
###
---
class: middle
# .hand[We...]
.huge[.green[have]] .hand[multiple data frames]
.huge[.pink[want]] .hand[to bring them together]
---
## Data: Women in science
Information on 10 women in science who changed the world
.small[
|name |
|:------------------|
|Ada Lovelace |
|Marie Curie |
|Janaki Ammal |
|Chien-Shiung Wu |
|Katherine Johnson |
|Rosalind Franklin |
|Vera Rubin |
|Gladys West |
|Flossie Wong-Staal |
|Jennifer Doudna |
]
.footnote[
Source: [Discover Magazine](https://www.discovermagazine.com/the-sciences/meet-10-women-in-science-who-changed-the-world)
]
---
## Inputs
.panelset[
.panel[.panel-name[professions]
```r
professions
```
```
## # A tibble: 10 x 2
## name profession
## <chr> <chr>
## 1 Ada Lovelace Mathematician
## 2 Marie Curie Physicist and Chemist
## 3 Janaki Ammal Botanist
## 4 Chien-Shiung Wu Physicist
## 5 Katherine Johnson Mathematician
## 6 Rosalind Franklin Chemist
## 7 Vera Rubin Astronomer
## 8 Gladys West Mathematician
## 9 Flossie Wong-Staal Virologist and Molecular Biologist
## 10 Jennifer Doudna Biochemist
```
]
.panel[.panel-name[dates]
```r
dates
```
```
## # A tibble: 8 x 3
## name birth_year death_year
## <chr> <dbl> <dbl>
## 1 Janaki Ammal 1897 1984
## 2 Chien-Shiung Wu 1912 1997
## 3 Katherine Johnson 1918 2020
## 4 Rosalind Franklin 1920 1958
## 5 Vera Rubin 1928 2016
## 6 Gladys West 1930 NA
## 7 Flossie Wong-Staal 1947 NA
## 8 Jennifer Doudna 1964 NA
```
]
.panel[.panel-name[works]
```r
works
```
```
## # A tibble: 9 x 2
## name known_for
## <chr> <chr>
## 1 Ada Lovelace first computer algorithm
## 2 Marie Curie theory of radioactivity, discovery of elem~
## 3 Janaki Ammal hybrid species, biodiversity protection
## 4 Chien-Shiung Wu confim and refine theory of radioactive bet~
## 5 Katherine Johnson calculations of orbital mechanics critical ~
## 6 Vera Rubin existence of dark matter
## 7 Gladys West mathematical modeling of the shape of the E~
## 8 Flossie Wong-Staal first scientist to clone HIV and create a m~
## 9 Jennifer Doudna one of the primary developers of CRISPR, a ~
```
]
]
---
## Desired output
```
## # A tibble: 10 x 5
## name profession birth~1 death~2 known~3
## <chr> <chr> <dbl> <dbl> <chr>
## 1 Ada Lovelace Mathematician NA NA first ~
## 2 Marie Curie Physicist and Chem~ NA NA theory~
## 3 Janaki Ammal Botanist 1897 1984 hybrid~
## 4 Chien-Shiung Wu Physicist 1912 1997 confim~
## 5 Katherine Johnson Mathematician 1918 2020 calcul~
## 6 Rosalind Franklin Chemist 1920 1958 <NA>
## 7 Vera Rubin Astronomer 1928 2016 existe~
## 8 Gladys West Mathematician 1930 NA mathem~
## 9 Flossie Wong-Staal Virologist and Mol~ 1947 NA first ~
## 10 Jennifer Doudna Biochemist 1964 NA one of~
## # ... with abbreviated variable names 1: birth_year,
## # 2: death_year, 3: known_for
```
---
## Inputs, reminder
.pull-left[
```r
names(professions)
```
```
## [1] "name" "profession"
```
```r
names(dates)
```
```
## [1] "name" "birth_year" "death_year"
```
```r
names(works)
```
```
## [1] "name" "known_for"
```
]
.pull-right[
```r
nrow(professions)
```
```
## [1] 10
```
```r
nrow(dates)
```
```
## [1] 8
```
```r
nrow(works)
```
```
## [1] 9
```
]
---
class: middle
# Joining data frames
---
## Joining data frames
```r
something_join(x, y)
```
- `left_join()`: all rows from x
- `right_join()`: all rows from y
- `full_join()`: all rows from both x and y
- `semi_join()`: all rows from x where there are matching values in y, keeping just columns from x
- `inner_join()`: all rows from x where there are matching values in y, return
all combination of multiple matches in the case of multiple matches
- `anti_join()`: return all rows from x where there are not matching values in y, never duplicate rows of x
- ...
---
## Setup
For the next few slides...
.pull-left[
```r
x
```
```
## # A tibble: 3 x 2
## id value_x
## <dbl> <chr>
## 1 1 x1
## 2 2 x2
## 3 3 x3
```
]
.pull-right[
```r
y
```
```
## # A tibble: 3 x 2
## id value_y
## <dbl> <chr>
## 1 1 y1
## 2 2 y2
## 3 4 y4
```
]
---
## `left_join()`
.pull-left[
<img src="img/left-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
left_join(x, y)
```
```
## # A tibble: 3 x 3
## id value_x value_y
## <dbl> <chr> <chr>
## 1 1 x1 y1
## 2 2 x2 y2
## 3 3 x3 <NA>
```
]
---
## `left_join()`
```r
professions %>%
* left_join(dates)
```
```
## # A tibble: 10 x 4
## name profession birth~1 death~2
## <chr> <chr> <dbl> <dbl>
## 1 Ada Lovelace Mathematician NA NA
## 2 Marie Curie Physicist and Chemist NA NA
## 3 Janaki Ammal Botanist 1897 1984
## 4 Chien-Shiung Wu Physicist 1912 1997
## 5 Katherine Johnson Mathematician 1918 2020
## 6 Rosalind Franklin Chemist 1920 1958
## 7 Vera Rubin Astronomer 1928 2016
## 8 Gladys West Mathematician 1930 NA
## 9 Flossie Wong-Staal Virologist and Molecular B~ 1947 NA
## 10 Jennifer Doudna Biochemist 1964 NA
## # ... with abbreviated variable names 1: birth_year,
## # 2: death_year
```
---
## `right_join()`
.pull-left[
<img src="img/right-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
right_join(x, y)
```
```
## # A tibble: 3 x 3
## id value_x value_y
## <dbl> <chr> <chr>
## 1 1 x1 y1
## 2 2 x2 y2
## 3 4 <NA> y4
```
]
---
## `right_join()`
```r
professions %>%
* right_join(dates)
```
```
## # A tibble: 8 x 4
## name profession birth~1 death~2
## <chr> <chr> <dbl> <dbl>
## 1 Janaki Ammal Botanist 1897 1984
## 2 Chien-Shiung Wu Physicist 1912 1997
## 3 Katherine Johnson Mathematician 1918 2020
## 4 Rosalind Franklin Chemist 1920 1958
## 5 Vera Rubin Astronomer 1928 2016
## 6 Gladys West Mathematician 1930 NA
## 7 Flossie Wong-Staal Virologist and Molecular Bi~ 1947 NA
## 8 Jennifer Doudna Biochemist 1964 NA
## # ... with abbreviated variable names 1: birth_year,
## # 2: death_year
```
---
## `full_join()`
.pull-left[
<img src="img/full-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
full_join(x, y)
```
```
## # A tibble: 4 x 3
## id value_x value_y
## <dbl> <chr> <chr>
## 1 1 x1 y1
## 2 2 x2 y2
## 3 3 x3 <NA>
## 4 4 <NA> y4
```
]
---
## `full_join()`
```r
dates %>%
* full_join(works)
```
```
## # A tibble: 10 x 4
## name birth_year death_year known_for
## <chr> <dbl> <dbl> <chr>
## 1 Janaki Ammal 1897 1984 hybrid species, biod~
## 2 Chien-Shiung Wu 1912 1997 confim and refine th~
## 3 Katherine Johnson 1918 2020 calculations of orbi~
## 4 Rosalind Franklin 1920 1958 <NA>
## 5 Vera Rubin 1928 2016 existence of dark ma~
## 6 Gladys West 1930 NA mathematical modelin~
## 7 Flossie Wong-Staal 1947 NA first scientist to c~
## 8 Jennifer Doudna 1964 NA one of the primary d~
## 9 Ada Lovelace NA NA first computer algor~
## 10 Marie Curie NA NA theory of radioactiv~
```
---
## `inner_join()`
.pull-left[
<img src="img/inner-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
inner_join(x, y)
```
```
## # A tibble: 2 x 3
## id value_x value_y
## <dbl> <chr> <chr>
## 1 1 x1 y1
## 2 2 x2 y2
```
]
---
## `inner_join()`
```r
dates %>%
* inner_join(works)
```
```
## # A tibble: 7 x 4
## name birth_year death_year known_for
## <chr> <dbl> <dbl> <chr>
## 1 Janaki Ammal 1897 1984 hybrid species, biodi~
## 2 Chien-Shiung Wu 1912 1997 confim and refine the~
## 3 Katherine Johnson 1918 2020 calculations of orbit~
## 4 Vera Rubin 1928 2016 existence of dark mat~
## 5 Gladys West 1930 NA mathematical modeling~
## 6 Flossie Wong-Staal 1947 NA first scientist to cl~
## 7 Jennifer Doudna 1964 NA one of the primary de~
```
---
## `semi_join()`
.pull-left[
<img src="img/semi-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
semi_join(x, y)
```
```
## # A tibble: 2 x 2
## id value_x
## <dbl> <chr>
## 1 1 x1
## 2 2 x2
```
]
---
## `semi_join()`
```r
dates %>%
* semi_join(works)
```
```
## # A tibble: 7 x 3
## name birth_year death_year
## <chr> <dbl> <dbl>
## 1 Janaki Ammal 1897 1984
## 2 Chien-Shiung Wu 1912 1997
## 3 Katherine Johnson 1918 2020
## 4 Vera Rubin 1928 2016
## 5 Gladys West 1930 NA
## 6 Flossie Wong-Staal 1947 NA
## 7 Jennifer Doudna 1964 NA
```
---
## `anti_join()`
.pull-left[
<img src="img/anti-join.gif" width="80%" style="background-color: #FDF6E3" style="display: block; margin: auto;" />
]
.pull-right[
```r
anti_join(x, y)
```
```
## # A tibble: 1 x 2
## id value_x
## <dbl> <chr>
## 1 3 x3
```
]
---
## `anti_join()`
```r
dates %>%
* anti_join(works)
```
```
## # A tibble: 1 x 3
## name birth_year death_year
## <chr> <dbl> <dbl>
## 1 Rosalind Franklin 1920 1958
```
---
## Putting it altogether
```r
professions %>%
left_join(dates) %>%
left_join(works)
```
```
## # A tibble: 10 x 5
## name profession birth~1 death~2 known~3
## <chr> <chr> <dbl> <dbl> <chr>
## 1 Ada Lovelace Mathematician NA NA first ~
## 2 Marie Curie Physicist and Chem~ NA NA theory~
## 3 Janaki Ammal Botanist 1897 1984 hybrid~
## 4 Chien-Shiung Wu Physicist 1912 1997 confim~
## 5 Katherine Johnson Mathematician 1918 2020 calcul~
## 6 Rosalind Franklin Chemist 1920 1958 <NA>
## 7 Vera Rubin Astronomer 1928 2016 existe~
## 8 Gladys West Mathematician 1930 NA mathem~
## 9 Flossie Wong-Staal Virologist and Mol~ 1947 NA first ~
## 10 Jennifer Doudna Biochemist 1964 NA one of~
## # ... with abbreviated variable names 1: birth_year,
## # 2: death_year, 3: known_for
```
---
class: middle
# Case study: Student records
---
## Student records
- Have:
- Enrolment: official university enrolment records
- Survey: Student provided info missing students who never filled it out and including students who filled it out but dropped the class
- Want: Survey info for all enrolled in class
--
.pull-left[
```r
enrolment
```
```
## # A tibble: 3 x 2
## id name
## <dbl> <chr>
## 1 1 Dave Friday
## 2 2 Hermine
## 3 3 Sura Selvarajah
```
]
.pull-right[
```r
survey
```
```
## # A tibble: 4 x 3
## id name username
## <dbl> <chr> <chr>
## 1 2 Hermine bakealongwithhermine
## 2 3 Sura surasbakes
## 3 4 Peter peter_bakes
## 4 5 Mark thebakingbuddha
```
]
---
## Student records
.panelset[
.panel[.panel-name[In class]
```r
enrolment %>%
* left_join(survey, by = "id")
```
```
## # A tibble: 3 x 4
## id name.x name.y username
## <dbl> <chr> <chr> <chr>
## 1 1 Dave Friday <NA> <NA>
## 2 2 Hermine Hermine bakealongwithhermine
## 3 3 Sura Selvarajah Sura surasbakes
```
]
.panel[.panel-name[Survey missing]
```r
enrolment %>%
* anti_join(survey, by = "id")
```
```
## # A tibble: 1 x 2
## id name
## <dbl> <chr>
## 1 1 Dave Friday
```
]
.panel[.panel-name[Dropped]
```r
survey %>%
* anti_join(enrolment, by = "id")
```
```
## # A tibble: 2 x 3
## id name username
## <dbl> <chr> <chr>
## 1 4 Peter peter_bakes
## 2 5 Mark thebakingbuddha
```
]
]
---
class: middle
# Case study: Grocery sales
---
## Grocery sales
- Have:
- Purchases: One row per customer per item, listing purchases they made
- Prices: One row per item in the store, listing their prices
- Want: Total revenue
--
.pull-left[
```r
purchases
```
```
## # A tibble: 5 x 2
## customer_id item
## <dbl> <chr>
## 1 1 bread
## 2 1 milk
## 3 1 banana
## 4 2 milk
## 5 2 toilet paper
```
]
.pull-right[
```r
prices
```
```
## # A tibble: 5 x 2
## item price
## <chr> <dbl>
## 1 avocado 0.5
## 2 banana 0.15
## 3 bread 1
## 4 milk 0.8
## 5 toilet paper 3
```
]
---
## Grocery sales
.panelset[
.panel[.panel-name[Total revenue]
.pull-left[
```r
purchases %>%
* left_join(prices)
```
```
## # A tibble: 5 x 3
## customer_id item price
## <dbl> <chr> <dbl>
## 1 1 bread 1
## 2 1 milk 0.8
## 3 1 banana 0.15
## 4 2 milk 0.8
## 5 2 toilet paper 3
```
]
.pull-right[
```r
purchases %>%
left_join(prices) %>%
* summarise(total_revenue = sum(price))
```
```
## # A tibble: 1 x 1
## total_revenue
## <dbl>
## 1 5.75
```
]
]
.panel[.panel-name[Revenue per customer]
.pull-left[
```r
purchases %>%
left_join(prices)
```
```
## # A tibble: 5 x 3
## customer_id item price
## <dbl> <chr> <dbl>
## 1 1 bread 1
## 2 1 milk 0.8
## 3 1 banana 0.15
## 4 2 milk 0.8
## 5 2 toilet paper 3
```
]
.pull-right[
```r
purchases %>%
left_join(prices) %>%
* group_by(customer_id) %>%
summarise(total_revenue = sum(price))
```
```
## # A tibble: 2 x 2
## customer_id total_revenue
## <dbl> <dbl>
## 1 1 1.95
## 2 2 3.8
```
]
]
]
---
## Acknowledgements
* This course builds on the materials from [Data Science in a Box](https://datasciencebox.org/) developed by Mine Çetinkaya-Rundel and are adapted under the [Creative Commons Attribution Share Alike 4.0 International](https://github.com/rstudio-education/datascience-box/blob/master/LICENSE.md)
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script>var slideshow = remark.create({
"ratio": "16:9",
"highlightLines": true,
"highlightStyle": "solarized-light",
"countIncrementalSlides": false
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0) {
text = code.textContent;
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
/^\$\$(.|\s)+\$\$$/.test(text) ||
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
code.outerHTML = code.innerHTML; // remove <code></code>
continue;
}
}
i++;
}
};
slideshow._releaseMath(document);
</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-MML-AM_CHTML';
if (location.protocol !== 'file:' && /^https?:/.test(script.src))
script.src = script.src.replace(/^https?:/, '');
document.getElementsByTagName('head')[0].appendChild(script);
})();
</script>
</body>
</html>