-
Notifications
You must be signed in to change notification settings - Fork 0
/
r4da-week04.html
2291 lines (2263 loc) · 198 KB
/
r4da-week04.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
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.2.475">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Viktoriia Semenova">
<meta name="dcterms.date" content="2023-09-27">
<title>Lab 4: Data Wrangling with dplyr and tidyr</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1.6em;
vertical-align: middle;
}
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
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<script src="r4da-week04_files/libs/clipboard/clipboard.min.js"></script>
<script src="r4da-week04_files/libs/quarto-html/quarto.js"></script>
<script src="r4da-week04_files/libs/quarto-html/popper.min.js"></script>
<script src="r4da-week04_files/libs/quarto-html/tippy.umd.min.js"></script>
<script src="r4da-week04_files/libs/quarto-html/anchor.min.js"></script>
<link href="r4da-week04_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="r4da-week04_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="r4da-week04_files/libs/bootstrap/bootstrap.min.js"></script>
<link href="r4da-week04_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="r4da-week04_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
</head>
<body class="fullcontent">
<div id="quarto-content" class="page-columns page-rows-contents page-layout-article">
<main class="content" id="quarto-document-content">
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<div class="quarto-title-block"><div><h1 class="title">Lab 4: Data Wrangling with <code>dplyr</code> and <code>tidyr</code></h1><button type="button" class="btn code-tools-button" id="quarto-code-tools-source"><i class="bi"></i> Code</button></div></div>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Author</div>
<div class="quarto-title-meta-contents">
<p>Viktoriia Semenova </p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">September 27, 2023</p>
</div>
</div>
</div>
</header>
<div style="page-break-after: always;"></div>
<section id="replication-text-beyond-keeping-peace-united-nations-effectiveness-in-the-midst-of-fighting" class="level2">
<h2 class="anchored" data-anchor-id="replication-text-beyond-keeping-peace-united-nations-effectiveness-in-the-midst-of-fighting">Replication Text: <em>Beyond Keeping Peace: United Nations Effectiveness in the Midst of Fighting</em></h2>
<blockquote class="blockquote">
<p>While United Nations peacekeeping missions were created to keep peace and perform post-conflict activities, since the end of the Cold War peacekeepers are more often deployed to active conflicts. Yet, we know little about their ability to manage ongoing violence. This article provides the first broad empirical examination of UN peacekeeping effectiveness in reducing battlefield violence in civil wars. We analyze how the number of UN peacekeeping personnel deployed influences the amount of battlefield deaths in all civil wars in Africa from 1992 to 2011. The analyses show that increasing numbers of armed military troops are associated with reduced battlefield deaths, while police and observers are not. Considering that the UN is often criticized for ineffectiveness, these results have important implications: if appropriately composed, UN peacekeeping missions reduce violent conflict.</p>
</blockquote>
<p>In the upcoming labs, we will refer to this article by Lisa Hultman, Jacob Kathman, and Megan Shannon, published in 2014 in the <em>American Political Science Review</em>. It is a good example of a well-structured empirical article (which you could use as a reference when writing your own papers), and replicating it would involve various common tasks in data analysis.</p>
</section>
<section id="exploring-the-dataset-un-peacekeeping-personnel-from-1990-2011-by-jakob-kathman" class="level2">
<h2 class="anchored" data-anchor-id="exploring-the-dataset-un-peacekeeping-personnel-from-1990-2011-by-jakob-kathman">Exploring the Dataset: UN peacekeeping personnel (from 1990-2011) by <a href="http://jacobkathman.weebly.com/research.html">Jakob Kathman</a></h2>
<p>The dataset can be downloaded from this page: <a href="https://kathmanundata.weebly.com/mission-personnel-dataset.html" class="uri">https://kathmanundata.weebly.com/mission-personnel-dataset.html</a></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">glimpse</span>(unpko)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>Rows: 6,175
Columns: 12
$ mission <chr> "BINUB", "BINUB", "BINUB", "BINUB", "BINUB", "BINUB"…
$ missioncountry <chr> "Burundi", "Burundi", "Burundi", "Burundi", "Burundi…
$ missionccode <dbl> 516, 516, 516, 516, 516, 516, 516, 516, 516, 516, 51…
$ missionccode2 <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
$ year <dbl> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…
$ month <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5…
$ yearmon <dbl> 2007.01, 2007.02, 2007.03, 2007.04, 2007.05, 2007.06…
$ troop <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
$ police <dbl> 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, …
$ militaryobservers <dbl> 0, 0, 3, 4, 4, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8…
$ total <dbl> 11, 11, 14, 15, 15, 15, 15, 18, 18, 20, 20, 20, 20, …
$ total2 <dbl> 11, 11, 14, 15, 15, 15, 15, 18, 18, 20, 20, 20, 20, …</code></pre>
</div>
</div>
</section>
<section id="basic-data-wrangling-functions" class="level2">
<h2 class="anchored" data-anchor-id="basic-data-wrangling-functions">Basic Data Wrangling Functions</h2>
<p>We can’t use all the beautiful plots until we have “wrangled” the data into a convenient shape and have all the variables we need for plotting. You have seen some of these functions already, but let’s now look at them a bit more systematically. Key wrangling functions include:</p>
<ul>
<li><p><code>filter()</code>: to pick out the <em>rows</em> we want to keep from a tibble.</p></li>
<li><p><code>select()</code>: to pick out the <em>columns</em> we want to keep from a tibble.</p></li>
<li><p><code>arrange()</code>: to sort the rows in a tibble, in either ascending or descending order.</p></li>
<li><p><code>mutate()</code>: to create new columns.</p></li>
<li><p><code>summarize()</code>: to create a new tibble comprised of summary statistics for one (or more) rows, depending on the use of the <code>.by</code> argument.</p></li>
</ul>
<section id="the-pipe-operator-again" class="level3">
<h3 class="anchored" data-anchor-id="the-pipe-operator-again">The pipe operator: <code>%>%</code> (again)</h3>
<p>The pipe operator (<code>%>%</code>) allows us to combine multiple operations in <code>R</code> into a single sequential <em>chain</em> of actions. Much like how the <code>+</code> sign has to come at the end of the line when constructing plots — because we are building the plot layer-by-layer — the pipe operator <code>%>%</code> has to come at the end of the line because we are building a data wrangling pipeline step-by-step. If you do not include the pipe operator, R assumes the next line of code is unrelated to the layers you built and you will get an error.</p>
</section>
<section id="filter-rows" class="level3">
<h3 class="anchored" data-anchor-id="filter-rows"><code>filter</code> rows</h3>
<p>The <code>filter()</code> function works much like the “Filter” option in Microsoft Excel. It allows you to specify criteria about the values of a variable in your dataset and then selects only the rows that match that criteria.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(missioncountry <span class="sc">==</span> <span class="st">"Rwanda"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 45 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 UNAMIR Rwanda 517 NA 1993 10 1993. 23
2 UNAMIR Rwanda 517 NA 1993 11 1993. 444
3 UNAMIR Rwanda 517 NA 1993 12 1993. 1012
4 UNAMIR Rwanda 517 NA 1994 1 1994. 1393
5 UNAMIR Rwanda 517 NA 1994 2 1994. 1844
6 UNAMIR Rwanda 517 NA 1994 3 1994. 2184
7 UNAMIR Rwanda 517 NA 1994 4 1994. 374
8 UNAMIR Rwanda 517 NA 1994 5 1994. 381
9 UNAMIR Rwanda 517 NA 1994 6 1994. 328
10 UNAMIR Rwanda 517 NA 1994 7 1994. 930
# ℹ 35 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
</div>
<p>Here are a few more operators that we can use here:</p>
<ul>
<li><code>></code> for “greater than”</li>
<li><code><</code> for “less than”</li>
<li><code>>=</code> for “greater than or equal to”</li>
<li><code><=</code> for “less than or equal to”</li>
<li><code>!=</code> for “not equal to”</li>
<li><code>%in%</code> for “inside”</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># everything but Rwanda (show, not store in the environment)</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(missioncountry <span class="sc">!=</span> <span class="st">"Rwanda"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,130 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 BINUB Burundi 516 NA 2007 1 2007. 0
2 BINUB Burundi 516 NA 2007 2 2007. 0
3 BINUB Burundi 516 NA 2007 3 2007. 0
4 BINUB Burundi 516 NA 2007 4 2007. 0
5 BINUB Burundi 516 NA 2007 5 2007. 0
6 BINUB Burundi 516 NA 2007 6 2007. 0
7 BINUB Burundi 516 NA 2007 7 2007. 0
8 BINUB Burundi 516 NA 2007 8 2007. 0
9 BINUB Burundi 516 NA 2007 9 2007. 0
10 BINUB Burundi 516 NA 2007 10 2007. 0
# ℹ 6,120 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># every row where troop index is ABOVE 10</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(troop <span class="sc">></span> <span class="dv">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 3,686 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 BONUCA Central African… 482 NA 2000 2 2000. 185
2 LBB Unknown -999 NA 1997 4 1997. 23
3 LBB Unknown -999 NA 1997 5 1997. 23
4 MINURCA Central African… 482 NA 1998 4 1998. 1218
5 MINURCA Central African… 482 NA 1998 5 1998. 1221
6 MINURCA Central African… 482 NA 1998 6 1998. 1362
7 MINURCA Central African… 482 NA 1998 7 1998. 1345
8 MINURCA Central African… 482 NA 1998 8 1998. 1345
9 MINURCA Central African… 482 NA 1998 9 1998. 1345
10 MINURCA Central African… 482 NA 1998 10 1998. 1347
# ℹ 3,676 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># every row where deaths_civilians index is EQUAL TO or ABOVE 10</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(troop <span class="sc">>=</span> <span class="dv">10</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 3,690 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 BONUCA Central African… 482 NA 2000 2 2000. 185
2 LBB Unknown -999 NA 1997 4 1997. 23
3 LBB Unknown -999 NA 1997 5 1997. 23
4 MINURCA Central African… 482 NA 1998 4 1998. 1218
5 MINURCA Central African… 482 NA 1998 5 1998. 1221
6 MINURCA Central African… 482 NA 1998 6 1998. 1362
7 MINURCA Central African… 482 NA 1998 7 1998. 1345
8 MINURCA Central African… 482 NA 1998 8 1998. 1345
9 MINURCA Central African… 482 NA 1998 9 1998. 1345
10 MINURCA Central African… 482 NA 1998 10 1998. 1347
# ℹ 3,680 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
</div>
<p>Furthermore, you can combine multiple criteria using operators that make comparisons:</p>
<ul>
<li><code>|</code> for “or”</li>
<li><code>&</code> for “and” (or just <code>,</code>)</li>
<li><code>!</code> for “not”</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> year <span class="sc">></span> <span class="dv">2005</span>,</span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> missioncountry <span class="sc">==</span> <span class="st">"Kosovo"</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 143 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 UNMIK Kosovo 347 NA 2008 2 2008. 0
2 UNMIK Kosovo 347 NA 2008 3 2008. 0
3 UNMIK Kosovo 347 NA 2008 4 2008. 0
4 UNMIK Kosovo 347 NA 2008 5 2008. 0
5 UNMIK Kosovo 347 NA 2008 6 2008. 0
6 UNMIK Kosovo 347 NA 2008 7 2008. 0
7 UNMIK Kosovo 347 NA 2008 8 2008. 0
8 UNMIK Kosovo 347 NA 2008 9 2008. 0
9 UNMIK Kosovo 347 NA 2008 10 2008. 0
10 UNMIK Kosovo 347 NA 2008 11 2008. 0
# ℹ 133 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(</span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> year <span class="sc">></span> <span class="dv">2000</span>,</span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> missioncountry <span class="sc">==</span> <span class="st">"Kosovo"</span> <span class="sc">|</span> missioncountry <span class="sc">==</span> <span class="st">"Burundi"</span>,</span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> total <span class="sc">></span> <span class="fu">mean</span>(total, <span class="at">na.rm =</span> T)</span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 19 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 ONUB Burundi 516 NA 2004 9 2004. 4324
2 ONUB Burundi 516 NA 2004 10 2004. 5262
3 ONUB Burundi 516 NA 2004 11 2004. 5291
4 ONUB Burundi 516 NA 2004 12 2004. 5190
5 ONUB Burundi 516 NA 2005 1 2005. 5188
6 ONUB Burundi 516 NA 2005 2 2005. 5174
7 ONUB Burundi 516 NA 2005 3 2005. 5169
8 ONUB Burundi 516 NA 2005 4 2005. 5186
9 ONUB Burundi 516 NA 2005 5 2005. 5168
10 ONUB Burundi 516 NA 2005 6 2005. 5314
11 ONUB Burundi 516 NA 2005 7 2005. 5316
12 ONUB Burundi 516 NA 2005 8 2005. 5344
13 ONUB Burundi 516 NA 2005 9 2005. 5400
14 ONUB Burundi 516 NA 2005 10 2005. 5364
15 ONUB Burundi 516 NA 2005 11 2005. 5336
16 ONUB Burundi 516 NA 2005 12 2005. 5170
17 ONUB Burundi 516 NA 2006 1 2006. 5153
18 ONUB Burundi 516 NA 2006 2 2006. 4396
19 ONUB Burundi 516 NA 2006 3 2006. 3741
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co"># same result but %in% instead or OR (|) for regions </span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">filter</span>(</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> year <span class="sc">></span> <span class="dv">2000</span>,</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> missioncountry <span class="sc">%in%</span> <span class="fu">c</span>(<span class="st">"Kosovo"</span>, <span class="st">"Burundi"</span>),</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> total <span class="sc">></span> <span class="fu">mean</span>(total, <span class="at">na.rm =</span> T)</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 19 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 ONUB Burundi 516 NA 2004 9 2004. 4324
2 ONUB Burundi 516 NA 2004 10 2004. 5262
3 ONUB Burundi 516 NA 2004 11 2004. 5291
4 ONUB Burundi 516 NA 2004 12 2004. 5190
5 ONUB Burundi 516 NA 2005 1 2005. 5188
6 ONUB Burundi 516 NA 2005 2 2005. 5174
7 ONUB Burundi 516 NA 2005 3 2005. 5169
8 ONUB Burundi 516 NA 2005 4 2005. 5186
9 ONUB Burundi 516 NA 2005 5 2005. 5168
10 ONUB Burundi 516 NA 2005 6 2005. 5314
11 ONUB Burundi 516 NA 2005 7 2005. 5316
12 ONUB Burundi 516 NA 2005 8 2005. 5344
13 ONUB Burundi 516 NA 2005 9 2005. 5400
14 ONUB Burundi 516 NA 2005 10 2005. 5364
15 ONUB Burundi 516 NA 2005 11 2005. 5336
16 ONUB Burundi 516 NA 2005 12 2005. 5170
17 ONUB Burundi 516 NA 2006 1 2006. 5153
18 ONUB Burundi 516 NA 2006 2 2006. 4396
19 ONUB Burundi 516 NA 2006 3 2006. 3741
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
</div>
</section>
<section id="arrange-rows" class="level3">
<h3 class="anchored" data-anchor-id="arrange-rows"><code>arrange</code> rows</h3>
<p><code>arrange()</code> allows us to sort/reorder a tibble’s (dataframe) rows according to the values of a specific variable. Unlike <code>filter()</code> or <code>select()</code>, <code>arrange()</code> does not remove any rows or columns from the tibble. Example:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(total) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 MINURSO Morocco 600 NA 1992 5 1992. -999
2 MINURSO Morocco 600 NA 1992 6 1992. -999
3 MINURSO Morocco 600 NA 1992 7 1992. -999
4 MINURSO Morocco 600 NA 2014 9 2014. -999
5 MINURSO Morocco 600 NA 2017 7 2017. -999
6 MINUSCA Central Africa… 482 NA 2014 9 2014. -999
7 MINUSCA Central Africa… 482 NA 2017 7 2017. -999
8 MINUSMA Mali 432 NA 2014 9 2014. -999
9 MINUSMA Mali 432 NA 2017 7 2017. -999
10 MINUSTAH Haiti 41 NA 2014 9 2014. -999
# ℹ 6,165 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(<span class="fu">desc</span>(total)) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 UNPROFOR Croatia-Bosnia… 344 346 1994 9 1994. 38614
2 UNPROFOR Croatia-Bosnia… 344 346 1994 10 1994. 38467
3 UNPROFOR Croatia-Bosnia… 344 346 1994 12 1994. 38332
4 UNPROFOR Croatia-Bosnia… 344 346 1995 2 1995. 38289
5 UNPROFOR Croatia-Bosnia… 344 346 1995 1 1995. 38207
6 UNPROFOR Croatia-Bosnia… 344 346 1994 11 1994. 38130
7 UNPROFOR Bosnia-Herzego… 346 NA 1995 3 1995. 37421
8 UNPROFOR Croatia-Bosnia… 344 346 1994 8 1994. 37442
9 UNPROFOR Croatia-Bosnia… 344 346 1994 7 1994. 36430
10 UNPROFOR Croatia-Bosnia… 344 346 1994 6 1994. 35128
# ℹ 6,165 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrange</span>(<span class="sc">-</span>total) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 12
mission missioncountry missionccode missionccode2 year month yearmon troop
<chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 UNPROFOR Croatia-Bosnia… 344 346 1994 9 1994. 38614
2 UNPROFOR Croatia-Bosnia… 344 346 1994 10 1994. 38467
3 UNPROFOR Croatia-Bosnia… 344 346 1994 12 1994. 38332
4 UNPROFOR Croatia-Bosnia… 344 346 1995 2 1995. 38289
5 UNPROFOR Croatia-Bosnia… 344 346 1995 1 1995. 38207
6 UNPROFOR Croatia-Bosnia… 344 346 1994 11 1994. 38130
7 UNPROFOR Bosnia-Herzego… 346 NA 1995 3 1995. 37421
8 UNPROFOR Croatia-Bosnia… 344 346 1994 8 1994. 37442
9 UNPROFOR Croatia-Bosnia… 344 346 1994 7 1994. 36430
10 UNPROFOR Croatia-Bosnia… 344 346 1994 6 1994. 35128
# ℹ 6,165 more rows
# ℹ 4 more variables: police <dbl>, militaryobservers <dbl>, total <dbl>,
# total2 <dbl></code></pre>
</div>
</div>
</section>
<section id="distinct-rows" class="level3">
<h3 class="anchored" data-anchor-id="distinct-rows"><code>distinct</code> rows</h3>
<p><code>distinct()</code> finds all the unique rows in a dataset, so in a technical sense, it primarily operates on the rows. Most of the time, however, you’ll want the distinct combination of some variables, so you can also optionally supply column names:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">distinct</span>(mission) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 82 × 1
mission
<chr>
1 BINUB
2 BINUH
3 BNUB
4 BONUCA
5 IPTF
6 LBB
7 MICAH
8 MINUCI
9 MINUGUA
10 MINUJUSTH
# ℹ 72 more rows</code></pre>
</div>
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">distinct</span>(mission, year) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 570 × 2
mission year
<chr> <dbl>
1 BINUB 2007
2 BINUB 2008
3 BINUB 2009
4 BINUB 2010
5 BINUH 2019
6 BNUB 2011
7 BNUB 2012
8 BONUCA 2000
9 IPTF 1996
10 LBB 1997
# ℹ 560 more rows</code></pre>
</div>
</div>
<p>The idea is similar to <code>count()</code> function you saw before, but <code>distinct()</code> does not provide us the infomratino aobut the sizes of groups.</p>
</section>
<section id="select-variables" class="level3">
<h3 class="anchored" data-anchor-id="select-variables"><code>select</code> variables</h3>
<p>This is used for subsetting variables (columns, not rows), deleting columns, and re-arranging columns.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(mission, total) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 2
mission total
<chr> <dbl>
1 BINUB 11
2 BINUB 11
3 BINUB 14
4 BINUB 15
5 BINUB 15
6 BINUB 15
7 BINUB 15
8 BINUB 18
9 BINUB 18
10 BINUB 20
# ℹ 6,165 more rows</code></pre>
</div>
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="sc">-</span>mission, <span class="sc">-</span>total) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 10
missioncountry missionccode missionccode2 year month yearmon troop police
<chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Burundi 516 NA 2007 1 2007. 0 11
2 Burundi 516 NA 2007 2 2007. 0 11
3 Burundi 516 NA 2007 3 2007. 0 11
4 Burundi 516 NA 2007 4 2007. 0 11
5 Burundi 516 NA 2007 5 2007. 0 11
6 Burundi 516 NA 2007 6 2007. 0 11
7 Burundi 516 NA 2007 7 2007. 0 11
8 Burundi 516 NA 2007 8 2007. 0 12
9 Burundi 516 NA 2007 9 2007. 0 12
10 Burundi 516 NA 2007 10 2007. 0 12
# ℹ 6,165 more rows
# ℹ 2 more variables: militaryobservers <dbl>, total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a><span class="co"># change the order of columns in dataset </span></span>
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">relocate</span>(mission, total) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 12
mission total missioncountry missionccode missionccode2 year month yearmon
<chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 BINUB 11 Burundi 516 NA 2007 1 2007.
2 BINUB 11 Burundi 516 NA 2007 2 2007.
3 BINUB 14 Burundi 516 NA 2007 3 2007.
4 BINUB 15 Burundi 516 NA 2007 4 2007.
5 BINUB 15 Burundi 516 NA 2007 5 2007.
6 BINUB 15 Burundi 516 NA 2007 6 2007.
7 BINUB 15 Burundi 516 NA 2007 7 2007.
8 BINUB 18 Burundi 516 NA 2007 8 2007.
9 BINUB 18 Burundi 516 NA 2007 9 2007.
10 BINUB 20 Burundi 516 NA 2007 10 2007.
# ℹ 6,165 more rows
# ℹ 4 more variables: troop <dbl>, police <dbl>, militaryobservers <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="co"># change the order of columns in dataset </span></span>
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb33-3"><a href="#cb33-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(mission, total, <span class="fu">everything</span>())</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 12
mission total missioncountry missionccode missionccode2 year month yearmon
<chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 BINUB 11 Burundi 516 NA 2007 1 2007.
2 BINUB 11 Burundi 516 NA 2007 2 2007.
3 BINUB 14 Burundi 516 NA 2007 3 2007.
4 BINUB 15 Burundi 516 NA 2007 4 2007.
5 BINUB 15 Burundi 516 NA 2007 5 2007.
6 BINUB 15 Burundi 516 NA 2007 6 2007.
7 BINUB 15 Burundi 516 NA 2007 7 2007.
8 BINUB 18 Burundi 516 NA 2007 8 2007.
9 BINUB 18 Burundi 516 NA 2007 9 2007.
10 BINUB 20 Burundi 516 NA 2007 10 2007.
# ℹ 6,165 more rows
# ℹ 4 more variables: troop <dbl>, police <dbl>, militaryobservers <dbl>,
# total2 <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb35"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="co"># only select variables starting with "y"</span></span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb35-3"><a href="#cb35-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(<span class="fu">starts_with</span>(<span class="st">"mission"</span>))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 4
mission missioncountry missionccode missionccode2
<chr> <chr> <dbl> <dbl>
1 BINUB Burundi 516 NA
2 BINUB Burundi 516 NA
3 BINUB Burundi 516 NA
4 BINUB Burundi 516 NA
5 BINUB Burundi 516 NA
6 BINUB Burundi 516 NA
7 BINUB Burundi 516 NA
8 BINUB Burundi 516 NA
9 BINUB Burundi 516 NA
10 BINUB Burundi 516 NA
# ℹ 6,165 more rows</code></pre>
</div>
</div>
</section>
<section id="mutate-variables" class="level3">
<h3 class="anchored" data-anchor-id="mutate-variables"><code>mutate</code> variables</h3>
<p><code>mutate()</code> takes existing columns and creates a new column or overwrites the existing one.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb37"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb37-1"><a href="#cb37-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="ot"><-</span> unpko <span class="sc">%>%</span></span>
<span id="cb37-2"><a href="#cb37-2" aria-hidden="true" tabindex="-1"></a> dplyr<span class="sc">::</span><span class="fu">mutate</span>(<span class="at">armed_forces =</span> troop <span class="sc">+</span> police,</span>
<span id="cb37-3"><a href="#cb37-3" aria-hidden="true" tabindex="-1"></a> <span class="at">yearmon =</span> <span class="fu">paste0</span>(year, <span class="st">"_"</span>, month))</span>
<span id="cb37-4"><a href="#cb37-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb37-5"><a href="#cb37-5" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb37-6"><a href="#cb37-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(armed_forces, missioncountry) <span class="sc">%>%</span> </span>
<span id="cb37-7"><a href="#cb37-7" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">armed_forces =</span> armed_forces <span class="sc">/</span> <span class="dv">100</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 2
armed_forces missioncountry
<dbl> <chr>
1 0.11 Burundi
2 0.11 Burundi
3 0.11 Burundi
4 0.11 Burundi
5 0.11 Burundi
6 0.11 Burundi
7 0.11 Burundi
8 0.12 Burundi
9 0.12 Burundi
10 0.12 Burundi
# ℹ 6,165 more rows</code></pre>
</div>
</div>
<p>Here is how we can remove remove variables with <code>mutate()</code> (although the same can be done with <code>select()</code> command):</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb39"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">select</span>(missioncountry, armed_forces) <span class="sc">%>%</span> </span>
<span id="cb39-3"><a href="#cb39-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(<span class="at">armed_forces =</span> <span class="cn">NULL</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 6,175 × 1
missioncountry
<chr>
1 Burundi
2 Burundi
3 Burundi
4 Burundi
5 Burundi
6 Burundi
7 Burundi
8 Burundi
9 Burundi
10 Burundi
# ℹ 6,165 more rows</code></pre>
</div>
</div>
<section id="recoding-variable-types" class="level4">
<h4 class="anchored" data-anchor-id="recoding-variable-types">Recoding Variable Types</h4>
<p>As you know from week 1, there are various data types in <code>R</code>, such as numeric, character, logical, factors. For some purposes, we need to recode one type into another. Changing the type also works through the <code>mutate()</code> in the same fashion, with the following syntax:</p>
<ul>
<li><code>var = as.character(var)</code></li>
<li><code>var = as.numeric(var)</code></li>
<li><code>var = as.logical(var)</code></li>
<li><code>var = as.factor(var)</code></li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb41"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mutate</span>(</span>
<span id="cb41-3"><a href="#cb41-3" aria-hidden="true" tabindex="-1"></a> <span class="at">armed_forces =</span> <span class="fu">as.character</span>(armed_forces) </span>
<span id="cb41-4"><a href="#cb41-4" aria-hidden="true" tabindex="-1"></a> ) <span class="sc">%>%</span></span>
<span id="cb41-5"><a href="#cb41-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">pull</span>(armed_forces) <span class="sc">%>%</span></span>
<span id="cb41-6"><a href="#cb41-6" aria-hidden="true" tabindex="-1"></a> <span class="fu">summary</span>()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> Length Class Mode
6175 character character </code></pre>
</div>
</div>
</section>
</section>
<section id="summarize-tibbles" class="level3">
<h3 class="anchored" data-anchor-id="summarize-tibbles"><code>summarize</code> tibbles</h3>
<p>We often need to calculate <em>summary statistics</em>, things like the <em>mean</em> (also called the average) and the <em>median</em> (the middle value). Other examples of summary statistics include the <em>sum</em>, the <em>minimum</em>, the <em>maximum</em>, and the <em>standard deviation</em>.</p>
<p>The function <code>summarize()</code> allows us to calculate these statistics on individual columns from a tibble. Example:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb43"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb43-2"><a href="#cb43-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(</span>
<span id="cb43-3"><a href="#cb43-3" aria-hidden="true" tabindex="-1"></a> <span class="at">mean_armed_forces =</span> <span class="fu">mean</span>(armed_forces, <span class="at">na.rm =</span> T),</span>
<span id="cb43-4"><a href="#cb43-4" aria-hidden="true" tabindex="-1"></a> <span class="at">sd_armed_forces =</span> <span class="fu">sd</span>(armed_forces, <span class="at">na.rm =</span> T) </span>
<span id="cb43-5"><a href="#cb43-5" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 1 × 2
mean_armed_forces sd_armed_forces
<dbl> <dbl>
1 3454. 5767.</code></pre>
</div>
</div>
<p>We can also let <code>R</code> perform operations within subgroups, rather than on the entire dataset:</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb45"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> </span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(mission) <span class="sc">%>%</span></span>
<span id="cb45-3"><a href="#cb45-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(</span>
<span id="cb45-4"><a href="#cb45-4" aria-hidden="true" tabindex="-1"></a> <span class="at">median_armed_forces =</span> <span class="fu">median</span>(armed_forces, <span class="at">na.rm =</span> T),</span>
<span id="cb45-5"><a href="#cb45-5" aria-hidden="true" tabindex="-1"></a> <span class="at">max_armed_forces =</span> <span class="fu">max</span>(armed_forces, <span class="at">na.rm =</span> T) </span>
<span id="cb45-6"><a href="#cb45-6" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 82 × 3
mission median_armed_forces max_armed_forces
<chr> <dbl> <dbl>
1 BINUB 10.5 12
2 BINUH 11 11
3 BNUB 0 1
4 BONUCA 3 188
5 IPTF 1197 1485
6 LBB 23 23
7 MICAH 1 1
8 MINUCI 0 0
9 MINUGUA 10.5 52
10 MINUJUSTH 1190 1280
# ℹ 72 more rows</code></pre>
</div>
<div class="sourceCode cell-code" id="cb47"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a><span class="co"># how many observations (months) are there per mission </span></span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span> <span class="co"># take dataset</span></span>
<span id="cb47-3"><a href="#cb47-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(mission) <span class="sc">%>%</span> <span class="co"># group by mission</span></span>
<span id="cb47-4"><a href="#cb47-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise</span>(<span class="at">count =</span> <span class="fu">n</span>())</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 82 × 2
mission count
<chr> <int>
1 BINUB 48
2 BINUH 3
3 BNUB 24
4 BONUCA 7
5 IPTF 5
6 LBB 2
7 MICAH 2
8 MINUCI 9
9 MINUGUA 42
10 MINUJUSTH 24
# ℹ 72 more rows</code></pre>
</div>
</div>
<p>This function can also be useful when we need to aggregate the dataset to another level. <code>unpko</code> dataset is on mission-month level, but let’s say we needed to aggregate it to mission-year instead.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb49"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb49-1"><a href="#cb49-1" aria-hidden="true" tabindex="-1"></a>unpko <span class="sc">%>%</span></span>
<span id="cb49-2"><a href="#cb49-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">group_by</span>(year) <span class="sc">%>%</span></span>
<span id="cb49-3"><a href="#cb49-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">summarise_if</span>(is.numeric, sum, <span class="at">na.rm =</span> <span class="cn">TRUE</span>) </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 30 × 10
year missionccode missionccode2 month troop police militaryobservers
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1990 19212 16800 624 -95904 -95904 -95904
2 1991 21667 15450 725 -102897 -102897 -102897
3 1992 56013 19942 925 128059 -58254 -68426
4 1993 72932 21672 1171 757326 36814 24218
5 1994 77434 21672 1260 823454 20127 28311
6 1995 74603 18212 1247 670226 19179 26578
7 1996 63959 17520 1335 267043 28277 17066
8 1997 59277 17520 1291 201476 34618 15302
9 1998 74316 17520 1266 124219 34632 11074
10 1999 81360 17520 1381 117935 36892 11094
# ℹ 20 more rows
# ℹ 3 more variables: total <dbl>, total2 <dbl>, armed_forces <dbl></code></pre>
</div>
<div class="sourceCode cell-code" id="cb51"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="co"># what is wrong in this code? how can you fix it?</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</section>
</section>
<section id="handling-missing-data" class="level2">
<h2 class="anchored" data-anchor-id="handling-missing-data">Handling Missing Data</h2>
<ul>
<li>Why do we care about missing data?</li>
</ul>
<p>There are two types of missing data:</p>
<ul>
<li><strong>Explicitly</strong> missing means you can see an <code>NA</code> in your data. <em>An explicit missing value is the presence of an absence.</em></li>
<li><strong>Implicitly</strong> missing means an entire row of data is simply absent from the data. <em>An implicit missing value is the absence of a presence.</em></li>
</ul>
<p>Here we will primarily talk about the first kind, i.e. handling <code>NA</code>s.</p>
<section id="basic-info" class="level3">
<h3 class="anchored" data-anchor-id="basic-info">Basic Info</h3>
<ul>
<li><code>NA</code> in <code>R</code> is a logical value, like <code>TRUE</code> and <code>FALSE</code></li>
<li>Sometimes <code>R</code> may import missing data wrong (e.g. treat <code>NA</code>s as character), so might need to explicitly recode it into <code>NA</code></li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb52"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a>example_numeric <span class="ot"><-</span> <span class="fu">c</span>(<span class="dv">8</span>, <span class="st">"NA"</span>, <span class="dv">9</span>, <span class="st">"missing"</span>, <span class="dv">10</span>, <span class="st">" "</span>, <span class="st">""</span>)</span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a>example_numeric </span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] "8" "NA" "9" "missing" "10" " " "" </code></pre>
</div>
<div class="sourceCode cell-code" id="cb54"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a>example_numeric <span class="sc">%>%</span> <span class="fu">as.numeric</span>() <span class="co"># will convert all character into NAs</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stderr">
<pre><code>Warning in example_numeric %>% as.numeric(): NAs introduced by coercion</code></pre>
</div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] 8 NA 9 NA 10 NA NA</code></pre>
</div>
</div>
<ul>
<li>Missing values represent the unknown so they are “contagious”: almost any operation involving an unknown value will also be unknown</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb57"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb57-1"><a href="#cb57-1" aria-hidden="true" tabindex="-1"></a><span class="cn">NA</span> <span class="sc">></span> <span class="dv">5</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] NA</code></pre>
</div>
<div class="sourceCode cell-code" id="cb59"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb59-1"><a href="#cb59-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cor</span>(</span>
<span id="cb59-2"><a href="#cb59-2" aria-hidden="true" tabindex="-1"></a> <span class="at">x =</span> <span class="fu">c</span>(<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>), </span>
<span id="cb59-3"><a href="#cb59-3" aria-hidden="true" tabindex="-1"></a> <span class="at">y =</span> <span class="fu">c</span>(<span class="cn">NA</span>, <span class="dv">3</span>, <span class="dv">4</span>)</span>
<span id="cb59-4"><a href="#cb59-4" aria-hidden="true" tabindex="-1"></a> )</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>[1] NA</code></pre>
</div>
</div>
</section>
<section id="inspecting-missing-values" class="level3">
<h3 class="anchored" data-anchor-id="inspecting-missing-values">Inspecting missing values</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb61"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb61-1"><a href="#cb61-1" aria-hidden="true" tabindex="-1"></a><span class="co"># check if each individual observation is NA</span></span>
<span id="cb61-2"><a href="#cb61-2" aria-hidden="true" tabindex="-1"></a><span class="fu">is.na</span>(unpko<span class="sc">$</span>troop)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[61] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[97] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[109] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[121] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[133] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[145] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[157] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[169] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[181] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[193] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[205] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[217] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[229] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[241] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[253] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[265] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[277] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[289] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[301] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[313] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[325] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[337] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[349] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[361] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[373] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[385] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[397] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[409] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[421] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[433] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[445] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[457] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[469] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[481] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[493] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[505] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[517] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[529] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[541] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[553] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[565] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[577] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[589] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[601] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[613] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[625] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[637] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[649] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[661] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[673] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[685] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[697] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[709] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[721] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[733] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[745] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[757] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[769] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[781] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[793] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[805] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[817] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[829] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[841] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[853] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[865] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[877] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[889] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[901] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[913] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[925] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[937] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[949] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[961] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[973] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[985] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[997] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1009] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1021] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1033] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1045] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1057] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1069] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1081] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1093] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1105] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1117] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1129] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1141] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1153] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1165] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1177] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1189] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1201] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1213] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1225] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1237] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1249] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1261] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1273] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1285] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1297] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1309] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1321] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1333] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1345] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1357] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1369] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1381] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1393] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1405] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1417] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1429] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1441] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1453] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1465] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1477] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1489] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1501] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1513] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1525] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1537] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1549] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1561] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1573] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1585] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1597] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1609] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1621] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1633] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1645] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1657] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1669] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1681] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1693] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1705] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1717] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1729] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1741] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1753] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1765] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1777] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1789] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1801] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1813] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1825] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1837] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1849] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1861] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1873] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1885] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1897] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1909] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1921] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1933] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1945] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1957] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1969] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1981] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[1993] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2005] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2017] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2029] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2041] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2053] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2065] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2077] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2089] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2101] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2113] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2125] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2137] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2149] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2161] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2173] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2185] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2197] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2209] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2221] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2233] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2245] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2257] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2269] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2281] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[2293] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE