-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_loading_and_cleaning.html
More file actions
2779 lines (2691 loc) · 159 KB
/
Copy path3_loading_and_cleaning.html
File metadata and controls
2779 lines (2691 loc) · 159 KB
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 lang="en"><head>
<script src="3_loading_and_cleaning_files/libs/clipboard/clipboard.min.js"></script>
<script src="3_loading_and_cleaning_files/libs/quarto-html/tabby.min.js"></script>
<script src="3_loading_and_cleaning_files/libs/quarto-html/popper.min.js"></script>
<script src="3_loading_and_cleaning_files/libs/quarto-html/tippy.umd.min.js"></script>
<link href="3_loading_and_cleaning_files/libs/quarto-html/tippy.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/quarto-html/light-border.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/quarto-html/quarto-syntax-highlighting-e26003cea8cd680ca0c55a263523d882.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<link href="3_loading_and_cleaning_files/libs/quarto-contrib/fontawesome6-0.1.0/all.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/quarto-contrib/fontawesome6-0.1.0/latex-fontsize.css" rel="stylesheet"><meta charset="utf-8">
<meta name="generator" content="quarto-1.6.39">
<meta name="dcterms.date" content="2026-02-19">
<title>Loading & Cleaning Data in R</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="3_loading_and_cleaning_files/libs/revealjs/dist/reset.css">
<link rel="stylesheet" href="3_loading_and_cleaning_files/libs/revealjs/dist/reveal.css">
<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 -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { 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 { display: inline-block; 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
{ color: #003b4f; background-color: #f1f3f5; }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span { color: #003b4f; } /* Normal */
code span.al { color: #ad0000; } /* Alert */
code span.an { color: #5e5e5e; } /* Annotation */
code span.at { color: #657422; } /* Attribute */
code span.bn { color: #ad0000; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #003b4f; font-weight: bold; } /* ControlFlow */
code span.ch { color: #20794d; } /* Char */
code span.cn { color: #8f5902; } /* Constant */
code span.co { color: #5e5e5e; } /* Comment */
code span.cv { color: #5e5e5e; font-style: italic; } /* CommentVar */
code span.do { color: #5e5e5e; font-style: italic; } /* Documentation */
code span.dt { color: #ad0000; } /* DataType */
code span.dv { color: #ad0000; } /* DecVal */
code span.er { color: #ad0000; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #ad0000; } /* Float */
code span.fu { color: #4758ab; } /* Function */
code span.im { color: #00769e; } /* Import */
code span.in { color: #5e5e5e; } /* Information */
code span.kw { color: #003b4f; font-weight: bold; } /* Keyword */
code span.op { color: #5e5e5e; } /* Operator */
code span.ot { color: #003b4f; } /* Other */
code span.pp { color: #ad0000; } /* Preprocessor */
code span.sc { color: #5e5e5e; } /* SpecialChar */
code span.ss { color: #20794d; } /* SpecialString */
code span.st { color: #20794d; } /* String */
code span.va { color: #111111; } /* Variable */
code span.vs { color: #20794d; } /* VerbatimString */
code span.wa { color: #5e5e5e; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="3_loading_and_cleaning_files/libs/revealjs/dist/theme/quarto-560a7fb8c8fb23736e113fee4ef09eaa.css">
<link href="3_loading_and_cleaning_files/libs/revealjs/plugin/quarto-line-highlight/line-highlight.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/revealjs/plugin/reveal-menu/menu.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/revealjs/plugin/reveal-menu/quarto-menu.css" rel="stylesheet">
<link href="3_loading_and_cleaning_files/libs/revealjs/plugin/quarto-support/footer.css" rel="stylesheet">
<style type="text/css">
.reveal div.sourceCode {
margin: 0;
overflow: auto;
}
.reveal div.hanging-indent {
margin-left: 1em;
text-indent: -1em;
}
.reveal .slide:not(.center) {
height: 100%;
}
.reveal .slide.scrollable {
overflow-y: auto;
}
.reveal .footnotes {
height: 100%;
overflow-y: auto;
}
.reveal .slide .absolute {
position: absolute;
display: block;
}
.reveal .footnotes ol {
counter-reset: ol;
list-style-type: none;
margin-left: 0;
}
.reveal .footnotes ol li:before {
counter-increment: ol;
content: counter(ol) ". ";
}
.reveal .footnotes ol li > p:first-child {
display: inline-block;
}
.reveal .slide ul,
.reveal .slide ol {
margin-bottom: 0.5em;
}
.reveal .slide ul li,
.reveal .slide ol li {
margin-top: 0.4em;
margin-bottom: 0.2em;
}
.reveal .slide ul[role="tablist"] li {
margin-bottom: 0;
}
.reveal .slide ul li > *:first-child,
.reveal .slide ol li > *:first-child {
margin-block-start: 0;
}
.reveal .slide ul li > *:last-child,
.reveal .slide ol li > *:last-child {
margin-block-end: 0;
}
.reveal .slide .columns:nth-child(3) {
margin-block-start: 0.8em;
}
.reveal blockquote {
box-shadow: none;
}
.reveal .tippy-content>* {
margin-top: 0.2em;
margin-bottom: 0.7em;
}
.reveal .tippy-content>*:last-child {
margin-bottom: 0.2em;
}
.reveal .slide > img.stretch.quarto-figure-center,
.reveal .slide > img.r-stretch.quarto-figure-center {
display: block;
margin-left: auto;
margin-right: auto;
}
.reveal .slide > img.stretch.quarto-figure-left,
.reveal .slide > img.r-stretch.quarto-figure-left {
display: block;
margin-left: 0;
margin-right: auto;
}
.reveal .slide > img.stretch.quarto-figure-right,
.reveal .slide > img.r-stretch.quarto-figure-right {
display: block;
margin-left: auto;
margin-right: 0;
}
</style>
</head>
<body class="quarto-light">
<div class="reveal">
<div class="slides">
<section id="title-slide" data-background-image="figures/dataset.png" data-background-position="95% 50%" data-background-size="40%" class="center">
<p class="absolute" style="top:0">Workshop: Dealing with Data in R</p>
<h1 class="title" style="padding-top: 150px;">Loading & Cleaning Data in R</h1>
<h3 class="subtitle" style="padding-top:5px;"><strong>I know the file exists, why doesn’t R?</strong></h3>
<p style="font-size:70%; padding-top: 120px">
<i class="fa-brands fa-github"></i> <a href="https://github.com/steffilazerte">steffilazerte</a><br>
<i class="fa-brands fa-mastodon"></i> <a href="https://fosstodon.org/@steffilazerte">@steffilazerte@fosstodon.org</a><br>
<i class="fa-brands fa-twitter"></i> <a href="https://twitter.com/steffilazerte">@steffilazerte</a><br>
<i class="fa-solid fa-globe"></i> <a href="https://steffilazerte.ca">steffilazerte.ca</a><br>
<img src="figures/steffi_logo.png" width="30%">
</p>
<p class="date">Compiled: 2026-02-19</p>
</section>
<section>
<section id="first-things-first" class="title-slide slide level1 center">
<h1>First things first</h1>
<div style="text-align:left; padding: 15px 200px 15px 200px">
<p><i class="fa-solid fa-floppy-disk" aria-label="floppy-disk"></i> Save previous script</p>
<p><i class="fa-solid fa-folder-open" aria-label="folder-open"></i> Open New File <br> <span class="small hang">(make sure you’re in the RStudio Project)</span></p>
<p><i class="fa-solid fa-pen" aria-label="pen"></i> Write <code>library(tidyverse)</code> at the top</p>
<p><i class="fa-solid fa-floppy-disk" aria-label="floppy-disk"></i> Save this new script <br> <span class="small hang">(consider names like <code>cleaning.R</code> or <code>3_loading_and_cleaning.R</code>)</span></p>
</div>
</section>
<section id="download-the-data-well-use-in-this-workshop" class="slide level2">
<h2>Download the data we’ll use in this workshop</h2>
<ol type="1">
<li>Create a ‘<strong>data</strong>’ folder in your RStudio project
<ul>
<li>In the “Files” pane click on the folder icon <strong>OR</strong></li>
<li>Navigate to your project folder via your computer’s file browser</li>
</ul></li>
</ol>
<img data-src="figures/files.png" style="width:30.0%" alt="Screenshot of the file viewer pane in RStudio with "New Folder" circled in red" class="r-stretch quarto-figure-center"><p class="caption">Click on “New Folder”</p><p><span style="margin-top:10px;"></span></p>
<ol start="2" type="1">
<li>Right-click “Save Link As..” and download these files to your <strong>data</strong> folder</li>
</ol>
<div class="columns">
<div class="column">
<ul>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/water_cleaned.xlsx">🔗<code>water_cleaned.xlsx</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/water_raw.csv">🔗<code>water_raw.csv</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/master_moch.txt">🔗<code>master_moch.txt</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/geolocators.csv">🔗<code>geolocators.csv</code></a></li>
</ul>
</div><div class="column">
<ul>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_size.txt">🔗<code>grain_size.txt</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_size2.csv">🔗<code>grain_size2.csv</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_meta.csv">🔗<code>grain_meta.csv</code></a></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/Sta%20A%20Data%202006-11-07.dmp">🔗<code>Sta A Data 2006-11-07.dmp</code></a></li>
</ul>
</div></div>
</section></section>
<section>
<section id="side-note" class="title-slide slide level1 center">
<h1>Side Note</h1>
<p><em>R base vs. <code>tidyverse</code></em></p>
</section>
<section id="r-base-vs.-tidyverse" class="slide level2">
<h2>R base vs. <code>tidyverse</code></h2>
<h3 id="r-base">R base</h3>
<ul>
<li>Basic R</li>
<li>Packages are installed and loaded by default</li>
<li>Base pipe <code>|></code> *</li>
</ul>
<p><img data-src="figures/logo_r.png" class="absolute" style="top: 10%; right: 20%; width: 20%; " alt="RStudio blue ball logo"></p>
<p><span class="footnote">*We’ll cover pipes soon 😁</span></p>
<div class="fragment">
<h3 id="tidyverse"><code>tidyverse</code></h3>
<ul>
<li>Collection of ‘new’ packages developed by a team closely affiliated with RStudio
<ul>
<li>e.g., <code>ggplot2</code>, <code>dplyr</code>, <code>tidyr</code>, <code>readr</code></li>
<li>Packages designed to work well together</li>
</ul></li>
<li>Use a slightly different syntax</li>
<li>tidyverse pipe <code>%>%</code> or base pipe <code>|></code> *</li>
</ul>
<p><img data-src="figures/hex_tidyverse.png" class="absolute" style="bottom: 0px; right: 40%; width: 15%; " alt="Hex logo for the tidyverse R package"></p>
</div>
<p><span class="fragment note absolute" style="left: 80%; bottom: 5%; width: 25%; ">Useful to know if functions are<br><strong><code>tidyverse</code></strong> or <strong>R base</strong></span></p>
</section>
<section id="dealing-with-data" class="slide level2">
<h2>Dealing with data</h2>
<div class="columns">
<div class="column" style="width:50%;">
<h3 id="loading-data">1. Loading data</h3>
<ul>
<li>Get your data into R</li>
</ul>
<h3 id="looking-for-problems">2. Looking for problems</h3>
<ul>
<li>Typos</li>
<li>Incorrectly loaded data</li>
</ul>
<h3 id="fixing-problems">3. Fixing problems</h3>
<ul>
<li>Corrections</li>
<li>Renaming</li>
<li>Dealing with NA’s</li>
</ul>
</div><div class="column" style="width:50%;">
<h3 id="setting-formats">4. Setting formats</h3>
<ul>
<li>Text,</li>
<li>Numbers</li>
<li>Factors</li>
<li>Dates</li>
</ul>
<h3 id="saving-your-data">5. Saving your data</h3>
</div></div>
</section></section>
<section>
<section id="loading-data-1" class="title-slide slide level1 center">
<h1>Loading Data</h1>
</section>
<section id="data-types-what-kind-of-data-do-you-have" class="slide level2">
<h2>Data types: What kind of data do you have?</h2>
<h3 id="specific-program-files">Specific program files</h3>
<div class="columns">
<div class="column" style="width:80%;">
<table class="caption-top">
<colgroup>
<col style="width: 25%">
<col style="width: 31%">
<col style="width: 20%">
<col style="width: 22%">
</colgroup>
<thead>
<tr class="header">
<th>Type</th>
<th>Extension</th>
<th>R Package</th>
<th>R function</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Excel</td>
<td>.xls, .xlsx</td>
<td><code>readxl</code>*</td>
<td><code>read_excel()</code></td>
</tr>
<tr class="even">
<td>Open Document</td>
<td>.ods</td>
<td><code>readODS</code></td>
<td><code>read_ods()</code></td>
</tr>
<tr class="odd">
<td>SPSS</td>
<td>.sav, .zsav, .por</td>
<td><code>haven</code></td>
<td><code>read_spss()</code></td>
</tr>
<tr class="even">
<td>SAS</td>
<td>.sas7bdat</td>
<td><code>haven</code></td>
<td><code>read_sas()</code></td>
</tr>
<tr class="odd">
<td>Stata</td>
<td>.dta</td>
<td><code>haven</code></td>
<td><code>read_dta()</code></td>
</tr>
<tr class="even">
<td>Database Files</td>
<td>.dbf</td>
<td><code>foreign</code></td>
<td><code>read.dbf()</code></td>
</tr>
</tbody>
</table>
</div></div>
<div class="fragment">
<h3 id="convenient-but">Convenient but…</h3>
<ul>
<li>Can be unreliable</li>
<li>Can take longer</li>
</ul>
</div>
<p><span class="fragment note absolute" style="left: 60%; bottom: 0px; ">For files that don’t change, better to save as a <code>*.csv</code><br> (Comma-separated-variables file)</span></p>
<p><img data-src="figures/hex_readxl.png" class="absolute" style="top: 0px; right: 0px; width: 16%; " alt="Hex logo for the readxl R package"> <span class="footnote">* part of the <code>tidyverse</code></span></p>
</section>
<section id="data-types-what-kind-of-data-do-you-have-1" class="slide level2">
<h2>Data types: What kind of data do you have?</h2>
<h3 id="general-text-files">General text files</h3>
<table class="caption-top">
<thead>
<tr class="header">
<th>Type</th>
<th>R base</th>
<th><code>readr</code> package *</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Comma separated</td>
<td><code>read.csv()</code></td>
<td><code>read_csv()</code>, <code>read_csv2()</code></td>
</tr>
<tr class="even">
<td>Tab separated</td>
<td><code>read.delim()</code></td>
<td><code>read_tsv()</code></td>
</tr>
<tr class="odd">
<td>Space separated</td>
<td><code>read.table()</code></td>
<td><code>read_table()</code></td>
</tr>
<tr class="even">
<td>Fixed-width</td>
<td><code>read.fwf()</code></td>
<td><code>read_fwf()</code></td>
</tr>
</tbody>
</table>
<p><img data-src="figures/hex_readr.png" class="absolute" style="top: 0px; right: 0px; width: 16%; " alt="Hex logo for the readr R package"> <span class="footnote">* part of the <code>tidyverse</code></span></p>
<div class="fragment spacer">
<ul>
<li><strong><code>readr</code> package</strong> especially useful for big data sets (fast!)</li>
<li>Error/warnings from <code>readr</code> are a bit more helpful</li>
</ul>
</div>
<div class="fragment note absolute" style="bottom: -15%; width: 50%; ">
<p><span class="large"><strong>We’ll focus on</strong></span></p>
<ul>
<li><code>readxl</code> package <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> <code>read_excel()</code><br>
</li>
<li><code>readr</code> package <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> <code>read_csv()</code>, <code>read_tsv()</code><br>
</li>
</ul>
</div>
</section>
<section id="where-is-my-data" class="slide level2">
<h2>Where is my data?</h2>
<h3 id="common-error">Common error</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb1-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"weather.csv"</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-error">
<pre><code>Error: 'weather.csv' does not exist in current working directory ('/home/steffi/Projects/Workshops/workshop-dealing-with-data').</code></pre>
</div>
</div>
<p>With no folder (just file name) R expects file to be in <strong>Working directory</strong></p>
<div class="fragment spacer">
<h3 id="working-directory-is">Working directory is:</h3>
<ul>
<li>Where your RStudio project is</li>
<li>Your home directory (My Documents, etc.) [If not using RStudio Projects]</li>
<li>Where you’ve set it (using <code>setwd()</code> or RStudio’s Session > Set Working Directory)</li>
</ul>
</div>
<div class="fragment note absolute" style="bottom: -5%; width: 50%; ">
<p><strong>Don’t</strong> use <code>setwd()</code><br>
<strong>Do</strong> use Projects in RStudio</p>
</div>
</section>
<section id="where-is-my-data-1" class="slide level2">
<h2>Where is my data?</h2>
<h3 id="a-note-on-file-paths-file-locations">A note on file paths (file locations)</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb3-1"><a href=""></a><span class="sc">/</span>home</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li>folders separated by <code>/</code></li>
<li><code>home</code> is a folder</li>
</ul>
</section>
<section id="where-is-my-data-2" class="slide level2">
<h2>Where is my data?</h2>
<h3 id="a-note-on-file-paths-file-locations-1">A note on file paths (file locations)</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb4-1"><a href=""></a><span class="sc">/</span>home<span class="sc">/</span>steffi<span class="sc">/</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li>folders separated by <code>/</code></li>
<li><code>home</code> and <code>steffi</code> are folders</li>
<li><code>steffi</code> is a folder inside of <code>home</code></li>
</ul>
</section>
<section id="where-is-my-data-3" class="slide level2">
<h2>Where is my data?</h2>
<h3 id="a-note-on-file-paths-file-locations-2">A note on file paths (file locations)</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb5-1"><a href=""></a><span class="sc">/</span>home<span class="sc">/</span>steffi<span class="sc">/</span>Documents<span class="sc">/</span>R Projects<span class="sc">/</span>mydata.csv</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li>folders separated by <code>/</code></li>
<li><code>home</code>, <code>steffi</code>, <code>Documents</code>, <code>R Projects</code> are folders</li>
<li><code>steffi</code> is inside of <code>home</code>, <code>Documents</code> is inside of <code>steffi</code>, etc.</li>
<li><code>mydata.csv</code> is a data file inside <code>R Projects</code> folder</li>
</ul>
<img data-src="figures/file_viewer.png" style="width:40.0%" alt="Screenshot of RStudio file pane showing mydata.csv" class="r-stretch quarto-figure-center"><p class="caption">RStudio Files Pane</p></section>
<section id="where-is-my-data-4" class="slide level2">
<h2>Where is my data?</h2>
<h3 id="absolute-paths"><strong>Absolute</strong> Paths</h3>
<div class="small left">
<table class="caption-top">
<thead>
<tr class="header">
<th>OS</th>
<th>Path</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>LINUX</strong></td>
<td>/home/steffi/Documents/R Projects/mydata.csv</td>
</tr>
<tr class="even">
<td><strong>WINDOWS</strong></td>
<td>C:/Users/steffi/My Documents/R Projects/mydata.csv</td>
</tr>
<tr class="odd">
<td><strong>MAC</strong></td>
<td>/users/steffi/Documents/R Projects/mydata.csv</td>
</tr>
</tbody>
</table>
</div>
<div class="fragment note absolute" style="top: 28%; left: 75%; ">
<p>Full location, folders and filename</p>
</div>
<div class="fragment">
<h3 class="spacer" id="relative-paths"><strong>Relative</strong> Paths</h3>
<div class="small left">
<table class="caption-top">
<colgroup>
<col style="width: 26%">
<col style="width: 73%">
</colgroup>
<thead>
<tr class="header">
<th>Path</th>
<th>Where to look</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>mydata.csv</td>
<td>Here (current directory)</td>
</tr>
<tr class="even">
<td>../mydata.csv</td>
<td>Go up one directory (../)</td>
</tr>
<tr class="odd">
<td>data/mydata.csv</td>
<td>Stay here, go into “data” folder (data/)</td>
</tr>
<tr class="even">
<td>../data/mydata.csv</td>
<td>Go up one directory (../), then into “data” folder (data/)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="fragment note absolute" style="top: 65%; left: 75%; ">
<p>Only <em>relative</em> info<br>
Use relative symbols (e.g., <code>../</code>)</p>
</div>
<div class="note fragment absolute" style="left: 25%; bottom: -5%; ">
<p>With RStudio ‘Projects’ only need to use <strong>relative</strong> paths</p>
</div>
</section>
<section id="keep-yourself-organized" class="slide level2">
<h2>Keep yourself organized</h2>
<h3 id="for-simple-projects">For simple projects</h3>
<ul>
<li>Create an ‘RStudio Project’ for each Project <!--(Chapter, Thesis, etc.) --></li>
<li>Create a specific “data” folder within each project (one per project)</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb6" data-code-line-numbers="1,3"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb6-1"><a href=""></a><span class="sc">-</span> Prospect Lake Quality <span class="co"># Project Folder</span></span>
<span id="cb6-2"><a href=""></a> <span class="sc">-</span> prospect_analysis.R</span>
<span id="cb6-3"><a href=""></a> <span class="sc">-</span> data <span class="co"># Data Folder </span></span>
<span id="cb6-4"><a href=""></a> <span class="sc">-</span> prospect_data_2017<span class="dv">-01</span><span class="fl">-01.</span>csv</span>
<span id="cb6-5"><a href=""></a> <span class="sc">-</span> prospect_data_2017<span class="dv">-02</span><span class="fl">-01.</span>csv</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="fragment">
<ul>
<li>Use <strong>relative</strong> paths to refer to this folder</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb7-1"><a href=""></a>d <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"data/prospect_data_2017-01-01.csv"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
</div>
</section></section>
<section>
<section id="lets-load-some-data" class="title-slide slide level1 center">
<h1>Let’s load some data!</h1>
</section>
<section id="a-reminder-about-assignments" class="slide level2">
<h2>A reminder about Assignments!</h2>
<ul>
<li><code><-</code></li>
<li>“Assign” an object to a handle/name</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb8-1"><a href=""></a>my_figure <span class="ot"><-</span> <span class="fu">ggplot</span>(<span class="at">data =</span> penguins, <span class="fu">aes</span>(<span class="at">x =</span> body_mass_g, <span class="at">y =</span> bill_length_mm)) <span class="sc">+</span></span>
<span id="cb8-2"><a href=""></a> <span class="fu">geom_point</span>()</span>
<span id="cb8-3"><a href=""></a></span>
<span id="cb8-4"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"my_data_spreadsheet.csv"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li><code>my_figure</code> is an R object, specifically a ggplot2 figure</li>
<li><code>my_data</code> is an R object, specifically a data.frame</li>
</ul>
<blockquote>
<p>To <em>use</em> your data, you need to load it <em>and</em> assign it to a handle/name</p>
</blockquote>
</section>
<section id="your-turn-load-some-data" class="slide level2 space-list">
<h2>Your turn: Load some data</h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/water_cleaned.xlsx">🔗<code>water_cleaned.xlsx</code></a></strong></p>
<div class="columns">
<div class="column" style="width:60%;">
<ol type="1">
<li>Load the package</li>
</ol>
<div class="cell">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb9-1"><a href=""></a><span class="fu">library</span>(readxl)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ol start="2" type="1">
<li>Read in the Excel file and assign to object <code>water</code></li>
</ol>
<div class="cell">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb10-1"><a href=""></a>water <span class="ot"><-</span> <span class="fu">read_excel</span>(<span class="st">"data/water_cleaned.xlsx"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ol start="3" type="1">
<li><p>Use <code>head()</code> and <code>tail()</code> functions to look at the data<br>
<span class="hang small">e.g., <code>head(water)</code> and <code>tail(water)</code></span></p></li>
<li><p>Click on the <code>water</code> object in your “Environment” pane to look at the whole data set</p></li>
</ol>
</div><div class="column" style="width:40%;">
<div class="quarto-figure quarto-figure-center">
<figure>
<p><img data-src="figures/tip_file_nav.gif" alt="GIF showing the dropdown menu that appears when you hit the 'tab' key inside the quotes when typing file locations"></p>
<figcaption>Use the <em>‘tab’</em> key in RStudio when typing in the file name for auto-complete</figcaption>
</figure>
</div>
</div></div>
</section>
<section id="your-turn-load-some-data-1" class="slide level2" data-visibility="visible">
<h2>Your turn: Load some data</h2>
<div class="small">
<div class="cell">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb11-1"><a href=""></a><span class="fu">library</span>(readxl)</span>
<span id="cb11-2"><a href=""></a>water <span class="ot"><-</span> <span class="fu">read_excel</span>(<span class="st">"data/water_cleaned.xlsx"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb12-1"><a href=""></a><span class="fu">head</span>(water)</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 × 6
river site element amount temperature year
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 Grasse Up stream Al 0.606 10.9 2019
2 Grasse Mid stream Al 0.425 8.68 2020
3 Grasse Down stream Al 0.194 8.75 2021
4 Oswegatchie Up stream Al 1 0.791 2022
5 Oswegatchie Mid stream Al 0.161 9.32 2023
6 Oswegatchie Down stream Al 0.0333 10.6 2019</code></pre>
</div>
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb14-1"><a href=""></a><span class="fu">tail</span>(water)</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 × 6
river site element amount temperature year
<chr> <chr> <chr> <dbl> <dbl> <dbl>
1 Raquette Up stream Zr 0.333 14.0 2023
2 Raquette Mid stream Zr 0.111 7.61 2019
3 Raquette Down stream Zr NA 7.36 2020
4 St. Regis Up stream Zr 0.889 7.94 2021
5 St. Regis Mid stream Zr 0.778 9.28 2022
6 St. Regis Down stream Zr 0.667 10.1 2023</code></pre>
</div>
</div>
</div>
<p><img data-src="figures/dataset.png" class="absolute" style="top: 0px; right: 0px; width: 45%; " alt="Screenshot of the data shown in the RStudio viewer pane"></p>
</section>
<section id="how-do-i-know-which-function-to-use" class="slide level2 space-list">
<h2>How do I know which function to use?</h2>
<h3 id="program-specific-files">Program-specific files</h3>
<ul>
<li>Files which only normally open in a particular program (e.g., Excel)</li>
<li><strong>Load with function from specific package (e.g. <code>read_excel</code> from readxl package)</strong></li>
</ul>
<h3 id="text-files">Text files</h3>
<ul>
<li>Files which open in notepad</li>
<li>Files which open in RStudio when you click on them in the Files Pane</li>
<li><strong>Load with function from readr package (e.g. <code>read_csv()</code>, <code>read_tsv()</code>, etc.)</strong></li>
</ul>
<h3 id="look-at-the-file-extension">Look at the file extension:</h3>
<ul>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/water_cleaned.xlsx">🔗<code>water_cleaned.xlsx</code></a> <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> Excel file <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> <code>read_excel()</code></li>
<li><a href="https://steffilazerte.ca/workshop-dealing-with-data/data/water_raw.csv">🔗<code>water_raw.csv</code></a> <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> Comma-separated-variables <i class="fa-solid fa-arrow-right" aria-label="arrow-right"></i> <code>read_csv()</code></li>
</ul>
<p><span class="note absolute fragment" style="left: 80%; bottom: 10%; width: 30%; ">But sometimes not clear…</span></p>
</section>
<section id="how-do-i-know-which-function-to-use-1" class="slide level2 space-list">
<h2>How do I know which function to use?</h2>
<h3 id="working-with-master_moch.txt">Working with: <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/master_moch.txt">🔗<code>master_moch.txt</code></a></h3>
<ul>
<li>In lower right-hand pane, click on <strong>Files</strong></li>
<li>Click on <strong>data</strong> folder</li>
<li>Click on <strong>master_moch.txt</strong></li>
<li>Click “View File” <span class="small">(if asked)</span></li>
</ul>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>ID region hab freq freq.sd p.notes
MCB02 kam 0.5266879074 3.9806600009 3.9806600009 0.4592592593
MCB03 kam -0.9707703735 4.1090031783 4.1090031783 0.5
MCB04 kam -0.9707703735 4.2463067674 4.2463067674 0.5151515152</code></pre>
</div>
</div>
<p><span class="note absolute" style="bottom: 8%; ">This <strong>does not</strong> read the file into R, but only shows you the contents as text.</span></p>
<p><span class="note fragment absolute" style="bottom: -5%; width: 60%; ">Hmm, not comma-separated, maybe tab-separated?</span></p>
</section>
<section id="how-do-i-know-which-function-to-use-2" class="slide level2">
<h2>How do I know which function to use?</h2>
<h3 id="peak">Peak:</h3>
<ul>
<li>Pick a read function with your best guess (<code>read_csv()</code> is a good start)</li>
<li>Use <code>n_max</code> to read only first few rows</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb17-1"><a href=""></a><span class="fu">read_csv</span>(<span class="st">"data/master_moch.txt"</span>, <span class="at">n_max =</span> <span class="dv">3</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 × 1
`ID\tregion\thab\tfreq\tfreq.sd\tp.notes`
<chr>
1 "MCB02\tkam\t0.5266879074\t3.9806600009\t3.9806600009\t0.4592592593"
2 "MCB03\tkam\t-0.9707703735\t4.1090031783\t4.1090031783\t0.5"
3 "MCB04\tkam\t-0.9707703735\t4.2463067674\t4.2463067674\t0.5151515152"</code></pre>
</div>
</div>
<div class="spacer">
<p><span class="note"><code>\t</code> means tab, so this is tab-separated data</span></p>
</div>
</section>
<section id="how-do-i-know-what-to-use" class="slide level2">
<h2>How do I know what to use?</h2>
<h3 id="peak-1">Peak:</h3>
<ul>
<li>Try again with <code>read_tsv()</code></li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb19-1"><a href=""></a><span class="fu">read_tsv</span>(<span class="st">"data/master_moch.txt"</span>, <span class="at">n_max =</span> <span class="dv">3</span>) <span class="co"># note change in function!</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 × 6
ID region hab freq freq.sd p.notes
<chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 MCB02 kam 0.527 3.98 3.98 0.459
2 MCB03 kam -0.971 4.11 4.11 0.5
3 MCB04 kam -0.971 4.25 4.25 0.515</code></pre>
</div>
</div>
<div class="spacer">
<p><span class="note">Excellent!</span></p>
</div>
</section></section>
<section>
<section id="specifics-of-loading-functions" class="title-slide slide level1 center">
<h1>Specifics of loading functions</h1>
</section>
<section id="col_names" class="slide level2 space-list">
<h2><code>col_names</code></h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/geolocators.csv">🔗<code>geolocators.csv</code></a></strong></p>
<p>
</p><div class="columns">
<div class="column" style="width:60%;">
<div class="cell">
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb21-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"data/geolocators.csv"</span>)</span>
<span id="cb21-2"><a href=""></a>my_data</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: 20 × 2
`02/05/11 22:29:59` `64`
<chr> <dbl>
1 02/05/11 22:31:59 64
2 02/05/11 22:33:59 38
3 02/05/11 22:35:59 38
4 02/05/11 22:37:59 34
5 02/05/11 22:39:59 30
6 02/05/11 22:41:59 34
7 02/05/11 22:43:59 40
8 02/05/11 22:45:59 46
9 02/05/11 22:47:59 48
10 02/05/11 22:49:59 46
# ℹ 10 more rows</code></pre>
</div>
</div>
<p>Oops?</p>
</div><div class="column fragment" style="width:40%;">
<ul>
<li><code>read_csv</code>, <code>read_tsv</code>, etc. assume that the first row contains the column names</li>
<li>This file doesn’t have headers</li>
</ul>
</div></div>
</section>
<section id="col_names-1" class="slide level2">
<h2><code>col_names</code></h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/geolocators.csv">🔗<code>geolocators.csv</code></a></strong></p>
<p>
</p><div class="columns">
<div class="column" style="width:48%;">
<h3 id="declare-no-headings">Declare no headings</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb23" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb23-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"data/geolocators.csv"</span>, </span>
<span id="cb23-2"><a href=""></a> <span class="at">col_names =</span> <span class="cn">FALSE</span>)</span>
<span id="cb23-3"><a href=""></a>my_data</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: 21 × 2
X1 X2
<chr> <dbl>
1 02/05/11 22:29:59 64
2 02/05/11 22:31:59 64
3 02/05/11 22:33:59 38
4 02/05/11 22:35:59 38
5 02/05/11 22:37:59 34
6 02/05/11 22:39:59 30
7 02/05/11 22:41:59 34
8 02/05/11 22:43:59 40
9 02/05/11 22:45:59 46
10 02/05/11 22:47:59 48
# ℹ 11 more rows</code></pre>
</div>
</div>
</div><div class="column" style="width:52%;">
<div class="fragment">
<h3 id="name-headings">Name headings</h3>
<div class="cell">
<div class="sourceCode cell-code" id="cb25" data-code-line-numbers="2"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb25-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"data/geolocators.csv"</span>, </span>
<span id="cb25-2"><a href=""></a> <span class="at">col_names =</span> <span class="fu">c</span>(<span class="st">"date"</span>, <span class="st">"light"</span>))</span>
<span id="cb25-3"><a href=""></a>my_data</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: 21 × 2
date light
<chr> <dbl>
1 02/05/11 22:29:59 64
2 02/05/11 22:31:59 64
3 02/05/11 22:33:59 38
4 02/05/11 22:35:59 38
5 02/05/11 22:37:59 34
6 02/05/11 22:39:59 30
7 02/05/11 22:41:59 34
8 02/05/11 22:43:59 40
9 02/05/11 22:45:59 46
10 02/05/11 22:47:59 48
# ℹ 11 more rows</code></pre>
</div>
</div>
</div>
</div></div>
</section>
<section id="skip-info-rows-before-data" class="slide level2">
<h2><code>skip</code> info rows before data</h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_size.txt">🔗<code>grain_size.txt</code></a></strong></p>
<div class="cell" data-highlight.output="[2,4,5,6]">
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb27-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_tsv</span>(<span class="st">"data/grain_size.txt"</span>)</span>
<span id="cb27-2"><a href=""></a>my_data</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: 36 × 7
`DATA DOWNLOAD: 2015-09-23` ...2 ...3 ...4 ...5 ...6 ...7
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 SYSTEM 001 <NA> <NA> <NA> <NA> <NA> <NA>
2 LOGGER X <NA> <NA> <NA> <NA> <NA> <NA>
3 lab_num CSP sample_num depth_lb csa msa fsa
4 3177 CSP01 CSP01-P-1-1 4 13.04 17.37 8.19
5 3178 CSP01 CSP01-P-1-2 12 10.74 16.9 7.92
6 3179 CSP01 CSP01-P-1-3 35 12.11 17.75 6.99
7 3180 CSP01 CSP01-P-1-4 53 17.61 18.16 6.29
8 3181 CSP01 CSP01-P-1-5 83 21.05 18.38 6.26
9 3182 CSP01 CSP01-P-1-6 105 19.02 18.43 6.28
10 3183 CSP08 CSP08-P-1-1 10 11.6 17.14 8.18
# ℹ 26 more rows</code></pre>
</div>
</div>
</section>
<section id="skip-info-rows-before-data-1" class="slide level2">
<h2><code>skip</code> info rows before data</h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_size.txt">🔗<code>grain_size.txt</code></a></strong></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb29-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_tsv</span>(<span class="st">"data/grain_size.txt"</span>)</span>
<span id="cb29-2"><a href=""></a>my_data</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div class="columns">
<div class="column" style="width:30%;">
<p><strong>Look at the file:</strong></p>
<ul>
<li>Click on <strong>Files</strong> tab</li>
<li>Click on <strong>data</strong> folder</li>
<li>Click on <strong>grain_size.txt</strong></li>
<li>Click <strong>“View file”</strong> <span class="small">(if asked)</span></li>
</ul>
</div><div class="column fragment" style="width:60%;">
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code>DATA DOWNLOAD: 2015-09-23
SYSTEM 001
LOGGER X
lab_num CSP sample_num depth_lb csa msa fsa
3177 CSP01 CSP01-P-1-1 4 13.04 17.37 8.19
3178 CSP01 CSP01-P-1-2 12 10.74 16.9 7.92
3179 CSP01 CSP01-P-1-3 35 12.11 17.75 6.99
3180 CSP01 CSP01-P-1-4 53 17.61 18.16 6.29
3181 CSP01 CSP01-P-1-5 83 21.05 18.38 6.26</code></pre>
</div>
</div>
</div></div>
<p><span class="note absolute fragment" style="left: 50%; bottom: 10%; "><strong>Ah ha!</strong><br>Metadata was stored at the top of the file</span></p>
</section>
<section id="skip-info-rows-before-data-2" class="slide level2">
<h2><code>skip</code> info rows before data</h2>
<p><strong>Working with <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/grain_size.txt">🔗<code>grain_size.txt</code></a></strong></p>
<ul>
<li>Add <code>skip = 3</code> to skip the first three rows</li>
</ul>
<div class="cell">
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb31-1"><a href=""></a>my_data <span class="ot"><-</span> <span class="fu">read_tsv</span>(<span class="st">"data/grain_size.txt"</span>, <span class="at">skip =</span> <span class="dv">3</span>)</span>
<span id="cb31-2"><a href=""></a>my_data</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: 33 × 7
lab_num CSP sample_num depth_lb csa msa fsa
<dbl> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 3177 CSP01 CSP01-P-1-1 4 13.0 17.4 8.19
2 3178 CSP01 CSP01-P-1-2 12 10.7 16.9 7.92
3 3179 CSP01 CSP01-P-1-3 35 12.1 17.8 6.99
4 3180 CSP01 CSP01-P-1-4 53 17.6 18.2 6.29
5 3181 CSP01 CSP01-P-1-5 83 21.0 18.4 6.26
6 3182 CSP01 CSP01-P-1-6 105 19.0 18.4 6.28
7 3183 CSP08 CSP08-P-1-1 10 11.6 17.1 8.18
8 3184 CSP08 CSP08-P-1-2 27 15.4 16.2 6.76
9 3185 CSP08 CSP08-P-1-3 90 14.9 15.8 7.12
10 3186 CSP02 CSP02-P-1-1 5 8.75 8.64 3.41
# ℹ 23 more rows</code></pre>
</div>
</div>
<p><span class="note absolute" style="left: 65%; bottom: 40%; ">Much better!</span></p>
</section>
<section id="your-turn-load-this-data-set" class="slide level2">
<h2>Your turn: Load this data set</h2>
<p><strong>Load Data: <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/Sta%20A%20Data%202006-11-07.dmp">🔗<code>Sta A Data 2006-11-07.dmp</code></a></strong></p>
<ol type="1">
<li>Look at the file</li>
<li>Decide which R function to use based on delimiter <span class="small">(comma, space, or tab?)</span></li>
<li>Any other options need to be specified?</li>
</ol>
<h3 id="it-should-look-like-this">It should look like this:</h3>
<div class="cell">
<div class="cell-output cell-output-stdout">
<pre><code># A tibble: 19 × 7
StartDate Time Frequency `Rate/Temp` Pwr Ant SD
<dbl> <time> <dbl> <dbl> <dbl> <chr> <dbl>
1 39022 17:15:36 150. 34.8 175 M0 0
2 39022 17:19:14 148. 19.2 72 M0 0
3 39022 17:19:25 148. 19.7 194 M1 0
4 39022 17:20:04 149. 33.8 104 M0 0
5 39022 17:20:17 149. 33.7 152 M1 0
6 39022 17:20:57 150. 34.2 188 M0 0
7 39022 17:22:50 148. 9.8 188 M0 0
# ℹ 12 more rows</code></pre>
</div>
</div>
<p><span class="note absolute" style="left: 80%; bottom: 17%; width: 40%; "><strong>Too Easy?</strong><br>Load some of your own tricky data</span> <span class="note absolute" style="left: 70%; bottom: 0px; width: 60%; "><strong>OR</strong><br>Try to load the second sheet of <code>water_cleaned.xlsx</code></span></p>
</section>
<section id="your-turn-load-this-data-set-1" class="slide level2" data-visibility="visible">
<h2>Your turn: Load this data set</h2>
<p><strong>Load Data: <a href="https://steffilazerte.ca/workshop-dealing-with-data/data/Sta%20A%20Data%202006-11-07.dmp">🔗<code>Sta A Data 2006-11-07.dmp</code></a></strong></p>
<div class="cell">
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode numberSource r number-lines code-with-copy"><code class="sourceCode r"><span id="cb34-1"><a href=""></a>telemetry <span class="ot"><-</span> <span class="fu">read_csv</span>(<span class="st">"data/Sta A Data 2006-11-07.dmp"</span>, <span class="at">skip =</span> <span class="dv">2</span>)</span>
<span id="cb34-2"><a href=""></a>telemetry</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 × 7
StartDate Time Frequency `Rate/Temp` Pwr Ant SD
<dbl> <time> <dbl> <dbl> <dbl> <chr> <dbl>
1 39022 17:15:36 150. 34.8 175 M0 0
2 39022 17:19:14 148. 19.2 72 M0 0
3 39022 17:19:25 148. 19.7 194 M1 0
4 39022 17:20:04 149. 33.8 104 M0 0
5 39022 17:20:17 149. 33.7 152 M1 0
6 39022 17:20:57 150. 34.2 188 M0 0
7 39022 17:22:50 148. 9.8 188 M0 0
# ℹ 12 more rows</code></pre>
</div>
</div>
</section>
<section id="your-turn-load-this-data-set-2" class="slide level2" data-visibility="visible">