-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlubridate.html
More file actions
executable file
Β·1027 lines (774 loc) Β· 23.7 KB
/
Copy pathlubridate.html
File metadata and controls
executable file
Β·1027 lines (774 loc) Β· 23.7 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="" xml:lang="">
<head>
<title>MAT381E-Week 7: Handling factors and dates in data</title>
<meta charset="utf-8" />
<meta name="author" content="GΓΌl Δ°nan" />
<meta name="date" content="2021-11-14" />
<script src="lubridate_files/header-attrs-2.11/header-attrs.js"></script>
<link href="lubridate_files/remark-css-0.0.1/default.css" rel="stylesheet" />
<script src="lubridate_files/fabric-4.3.1/fabric.min.js"></script>
<link href="lubridate_files/xaringanExtra-scribble-0.0.1/scribble.css" rel="stylesheet" />
<script src="lubridate_files/xaringanExtra-scribble-0.0.1/scribble.js"></script>
<script>document.addEventListener('DOMContentLoaded', function() { window.xeScribble = new Scribble({"pen_color":["#FF0000"],"pen_size":3,"eraser_size":30,"palette":[]}) })</script>
<link href="lubridate_files/tile-view-0.2.6/tile-view.css" rel="stylesheet" />
<script src="lubridate_files/tile-view-0.2.6/tile-view.js"></script>
<link href="lubridate_files/animate.css-3.7.2/animate.xaringan.css" rel="stylesheet" />
<link href="lubridate_files/tachyons-4.12.0/tachyons.min.css" rel="stylesheet" />
<link href="lubridate_files/panelset-0.2.6/panelset.css" rel="stylesheet" />
<script src="lubridate_files/panelset-0.2.6/panelset.js"></script>
<link rel="stylesheet" href="xaringan-themer.css" type="text/css" />
</head>
<body>
<textarea id="source">
class: left, middle, my-title, title-slide
# MAT381E-Week 7: Handling factors and dates in data
### GΓΌl Δ°nan
### Department of Mathematics<br/>Istanbul Technical University
### November 14, 2021
---
class: left
# Outline
* Introduction to `lubridate` package.
*01-lubridate_casestudy.Rmd
---
# Overview
- Up to now, we have dealt with: numeric, character, logical, and factor type of vectors.
- In data science projects, we may encounter variables that are **dates** and **times**.
- **Dates** and **times** can be used to quantify when exactly a certain event occurs and can help us understand chronological relationships.
---
class: middle, center
#### What do you see in this graphic?
<img src="images/gtrend.png" width="80%" height="100%" />
---
#### Date-time functions/classes
- Luckily, `R` provides several options for dealing with **date** and **date/time** data.
- Just as numbers and strings have their own class in `R`, **date** and **date/time** objects have their own class too.
- In base `R`, the built-in `as.Date()` function with `Date` class handles dates (without times); and the `as.POSIXct()` function with `POSIXct` class and `as.POSIXlt()` function with `POSIXlt` class allow for dates and times with control for **time zones**.
|Type |Function |Class | Description |
|:--------------|:-------------|:---------|:----------------------------------------------------|
|date |`as.Date()` |`Date` | represent calendar dates. |
|date-time |`as.POSIXct()`|`POSIXct` | stores seconds since epoch (since `January 1, 1970`).|
|date-time |`as.POSIXlt()`|`POSIXlt` | stores a list of day, month, year, hour, minute, second, etc.|
- Note: POSIX stands for `Portable Operating System Interface` and it is a family of standards specified by the `IEEE Computer Society` for maintaining compatibility between different operating systems.
- The POSIX classes are especially useful when time zone manipulation is important.
- `ct` stands for calendar time.
---
- Computer languages usually use `January 1, 1970`
as the _epoch_ which is an origin (reference) day so that the dates can be converted to numbers. Dates older than the origin are stored as negative integers.
- Similarly, in `R`, except for the `POSIXlt` class, dates are stored internally as the number of days or seconds from `January 1, 1970`.
- The `POSIXlt` class stores date/time values as a list of components (day, month, year, etc.) making it easy to extract these parts.
- Unless you need the list nature of the `POSIXlt` class, the `POSIXct` class is the usual choice for storing dates in `R`.
---
- Let's get the current system date and time.
```r
# get system date
Sys.Date()
```
```
#> [1] "2021-11-14"
```
```r
# check the class
class(Sys.Date())
```
```
#> [1] "Date"
```
```r
# get the system time
Sys.time()
```
```
#> [1] "2021-11-14 18:25:35 +03"
```
```r
# check the class
class(Sys.time())
```
```
#> [1] "POSIXct" "POSIXt"
```
---
class: middle, center
<img src="images/date.jpeg" width="60%" />
---
<style type="text/css">
.pull-left {
float: left;
width: 50%;
}
.pull-right {
float: right;
width: 50%;
}
</style>
#### Date format
.pull-left[
- There are **many ways** to write a date and date formats vary **across the world**.
- Having **different formats** could be confusing for people that come from different countries to understand.
- The [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) recommends writing the date as year, then month, then the day: `YYYY-MM-DD` and uses the 24 hour clock system.
- This default format used in `R` is also the `ISO 8601 standard` for date/time.
```r
Sys.time()
```
```
#> [1] "2021-11-14 18:25:35 +03"
```
]
.pull-right[
<img src="images/iso.png" width="100%" height="100%" />
]
---
- We can create date objects through `as.Date()` function in base `R`.
```r
#check
class(2021-10-04)
```
```
#> [1] "numeric"
```
```r
class("2021-10-04")
```
```
#> [1] "character"
```
```r
#create a data object in base R
school_start_date <- as.Date("2021-10-04")
class(school_start_date)
```
```
#> [1] "Date"
```
```r
#number of days since 1970-01-01
unclass(school_start_date)
```
```
#> [1] 18904
```
```r
#How long has been since the school started?
Sys.Date()-school_start_date
```
```
#> Time difference of 41 days
```
---
- Many of the statistical summary functions, like mean, min, max, etc are able to transparently handle date objects.
```r
important_dates <- as.Date(c("2021-11-01","2021-10-01","2021-09-01"))
important_dates
```
```
#> [1] "2021-11-01" "2021-10-01" "2021-09-01"
```
```r
min(important_dates)
```
```
#> [1] "2021-09-01"
```
```r
max(important_dates)
```
```
#> [1] "2021-11-01"
```
- The `by=argument` to the `seq()` function can be specified in any units of time that the function accepts, making it very easy to generate sequences of dates.
```r
seq(from=as.Date('2021-10-04'), to=as.Date('2022-01-01'), by='10 days') #1 day, 10 days, 2 weeks, 3 months
```
```
#> [1] "2021-10-04" "2021-10-14" "2021-10-24" "2021-11-03" "2021-11-13"
#> [6] "2021-11-23" "2021-12-03" "2021-12-13" "2021-12-23"
```
- where unit of time in `by` argument can be: "secs", "mins", "hours", "days", "weeks", and "months".
---
- The `as.Date()` function allows a variety of **input formats** through the `format` input argument.
| Code | Value |
|:-----|:--------------|
| %d | Day of the month (decimal number)|
| %m | Month (decimal number)|
| %b | Month (abbreviated)|
| %B | Month (full name)|
| %y | Year (2 digit)|
| %Y | Year (4 digit)|
```r
#convert it into a data object with YYYY-MM-DD
#format argument tells the input structure, output is always in YYYY-MM-DD
as.Date('15-11-2021', format = '%d-%m-%Y')
```
```
#> [1] "2021-11-15"
```
```r
#convert it into a data object with YYYY-MM-DD
#format argument tells the input structure, output is always in YYYY-MM-DD
as.Date('November 15, 2021', format='%B %d, %Y')
```
```
#> [1] "2021-11-15"
```
---
- You can also change the format of the date into another date form through `format()` function.
```r
Sys.Date()
```
```
#> [1] "2021-11-14"
```
```r
format(Sys.Date(), '%B %d, %Y')
```
```
#> [1] "November 14, 2021"
```
- See YAML part of my slides!..
```r
---
title: "MAT381E-Week 7: Handling dates in data"
subtitle: ""
author: "GΓΌl Δ°nan"
institute: "Department of Mathematics<br/>Istanbul Technical University"
date: "`r format(Sys.Date(), '%B %d, %Y')`"
---
```
---
- The default input format for `POSIX` dates consists of the year, followed by the month and day, separated by dashes; for date/time values, the date may be followed by **white space** and a time in the form `hour:minutes:seconds` or `hour:minutes`; thus, the following are examples of valid `POSIX` date or date/time objects:
```r
#create POSIX objects
#no need format argument since it is already in YYYY-MM-DD format
release_date <- as.POSIXct("2019-12-12")
release_date
```
```
#> [1] "2019-12-12 +03"
```
```r
class(release_date)
```
```
#> [1] "POSIXct" "POSIXt"
```
```r
unclass(release_date)
```
```
#> [1] 1576098000
#> attr(,"tzone")
#> [1] ""
```
```r
#create POSIX objects
release_date <- as.POSIXct("2019-12-12 08:05:03")
class(release_date)
```
```
#> [1] "POSIXct" "POSIXt"
```
```r
release_date
```
```
#> [1] "2019-12-12 08:05:03 +03"
```
---
```r
#create POSIX objects
release_date <- as.POSIXlt("2019-12-12 08:05:03")
class(release_date)
```
```
#> [1] "POSIXlt" "POSIXt"
```
```r
release_date
```
```
#> [1] "2019-12-12 08:05:03 +03"
```
```r
release_date$hour #you can get the components
```
```
#> [1] 8
```
---
- Use:
- `Date` when there is no time component,
- `POSIXct` when dealing with time and time zones, and
- `POSIXlt` when you want to access/extract the different components.
---
#### Example: Google Trends results of Δ°TΓ
- I imported _Google Trend Search_ results for Δ°TΓ between January 1, 2021 and November 1, 2021 via [gtrendsR](https://cran.r-project.org/web/packages/gtrendsR/) package. Note that my query results are very limited and restricted to Turkey location only.
.panelset[
.panel[.panel-name[Data]
```r
google_trends <- readr::read_csv("data/google_trends_itu.csv")
head(google_trends, 3)
```
```
#> # A tibble: 3 Γ 2
#> date Δ°TΓ_TR
#> <date> <dbl>
#> 1 2021-01-03 39
#> 2 2021-01-10 42
#> 3 2021-01-17 39
```
- The variable `date` in `google.trends` data looks like a character. But, actually, it is `date`:
```r
library(tidyverse)
google_trends %>%
str()
```
```
#> spec_tbl_df [44 Γ 2] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
#> $ date : Date[1:44], format: "2021-01-03" "2021-01-10" ...
#> $ Δ°TΓ_TR: num [1:44] 39 42 39 43 42 49 56 69 58 37 ...
#> - attr(*, "spec")=
#> .. cols(
#> .. date = col_date(format = ""),
#> .. Δ°TΓ_TR = col_double()
#> .. )
#> - attr(*, "problems")=<externalptr>
```
```r
class(google_trends$date)
```
```
#> [1] "Date"
```
]
.panel[.panel-name[Code]
```r
ggplot2::ggplot(data = google_trends) +
geom_line(aes(x = date, y = Δ°TΓ_TR)) +
scale_x_date(limits = as.Date(c("2021-01-01","2021-11-01")),
date_breaks = "1 month" )+
geom_vline(aes(xintercept = as.Date("2021-10-03")), color="red") +
ggtitle("Google Trends search results for Δ°TΓ in 2021") +
ylab("Number of Searches") +
xlab("Date") +
theme_bw()
```
]
.panel[.panel-name[Output]
<img src="lubridate_files/figure-html/unnamed-chunk-27-1.png" width="40%" />
]
]
---
- Plotting functions in `ggplot2` are aware of dates which means that, for example, a scatter plot can use the **numeric representation**
to decide on the position of the point, but include the **string in the labels** via `scale_*_date()` function:
.panelset[
.panel[.panel-name[Code]
```r
library(ggplot2)
ggplot(data = google_trends) +
geom_line(aes(x = date, y = Δ°TΓ_TR)) +
* scale_x_date(limits = as.Date(c("2021-01-01","2021-11-01")),
* date_breaks = "1 month", date_labels = "%b-%d") +
geom_vline(aes(xintercept = as.Date("2021-10-03")), color="red") +
ggtitle("Google Trends search results for Δ°TΓ in 2021") +
ylab("Number of Searches") +
xlab("Date") +
theme_bw()
#more: https://www.statworx.com/at/blog/customizing-time-and-date-scales-in-ggplot2/
```
]
.panel[.panel-name[Output]
<img src="lubridate_files/figure-html/unnamed-chunk-29-1.png" width="40%" />
]
]
---
class: middle, center

---
# lubridate package
- The `tidyverse ecosystem` includes [lubridate](https://lubridate.tidyverse.org/) package for dealing with **date-times** and **time-spans**.
- It is fast and user friendly helping with:
- Parsing of date-time data,
- Extraction and updating of components of a date-time, and
- Algebraic manipulation on date-time and time-span objects.
- First, to be able to use the functionality of `lubridate` we have to load the package:
```r
# The easiest way to get lubridate is to load the whole tidyverse:
# library(tidyverse) or
# Alternatively, load just lubridate:
library(lubridate)
```
---
#### Parsing dates and times (Converting strings or numbers to date-times)
- The `lubridate` package has a number of functions to convert **strings** to **date** and **date-time** objects.
- Here, we simply try to **match the characters to the pattern of the date-time** we are trying to parse.
- The goal is to end up with a date-time in the form: `YYYY-MM-DD HH:MM:SS`.
- For parsing the date, in `lubridate` we can use a combination of the letters βdβ, βmβ, βyβ (standing for day, month, year).
- Use the functions below whose name replicates the order.
|Function |Description |
|----------|-------------------------------------------|
|`ymd()` |converts characters into YYYY-MM-DD format.|
|`ydm()` |converts characters into YYYY-MM-DD format.|
|`mdy()` |converts characters into YYYY-MM-DD format.|
|`dmy()` |converts characters into YYYY-MM-DD format.|
|`hms()` |converts characters into HH:MM:SS format. |
|`hm()` |converts characters into HH:MM format. |
|`h()` |converts characters into HH format. |
---
```r
# When is International Women's day?
library(lubridate)
#pattern is year, month, day
ymd("20210308")
```
```
#> [1] "2021-03-08"
```
```r
#pattern is year, day, month
ydm("20210803")
```
```
#> [1] "2021-03-08"
```
```r
#pattern is month, day, year
mdy("03-08-2021")
```
```
#> [1] "2021-03-08"
```
```r
#pattern is day, month, year
dmy("08/03/2021")
```
```
#> [1] "2021-03-08"
```
```r
#all of them are converted to the YYYY-MM-DD format.
```
---
```r
#if we thing that these strings are in year-month-day format,
#then put all of them in a standard year-month-day format.
x <- c(20090101, "2009-01-02", "2009 01 03", "2009-1-4",
"2009-1, 5", "Created on 2009 1 6", "200901 !!! 07")
ymd(x)
```
```
#> [1] "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05"
#> [6] "2009-01-06" "2009-01-07"
```
---
- A very similar technique can be used to parse times:
```r
#there is no other functions such as smh() etc.
#other versions are hm(), h()
hms("20:30:10")
```
```
#> [1] "20H 30M 10S"
```
- Now if we come across a variable that includes a date and time we can join relevant functions together with an β_β to parse a date-time.
```r
ymd_hms("2006/03/19 20:30:10")
```
```
#> [1] "2006-03-19 20:30:10 UTC"
```
```r
ydm_hms("2006/19/03 20:30:10")
```
```
#> [1] "2006-03-19 20:30:10 UTC"
```
```r
mdy_hms("03/19/2006 20:30:10")
```
```
#> [1] "2006-03-19 20:30:10 UTC"
```
```r
dmy_hms("19/03/2006 20:30:10")
```
```
#> [1] "2006-03-19 20:30:10 UTC"
```
```r
#all of them are converted to the YYYY-MM-DD hh:mm:ss format.
```
- The phrase **Coordinated Universal Time (UTC)** in the output represents the time-zone and by default should be UTC, this stands for universal time coordinated.
---
#### GET components of date-times
- We can use helper functions to get a relevant component in `data-time` objects.
|Function |Description |
|-----------------|-------------------|
|`date()` |Date component |
|`year()` |Year component |
|`month(, label)` |Month component |
|`day()` |Day of month |
|`week()` |Week of the year |
|`wday(, label)` |Day of week |
|`yday()` |Day of year |
|`hour()` |Hour |
|`minute()` |Minute |
|`second()` |Second |
---
```r
womensday <- ymd("2021/03/08")
#replaces "/" with "-".
year(womensday)
```
```
#> [1] 2021
```
```r
month(womensday)
```
```
#> [1] 3
```
```r
week(womensday)
```
```
#> [1] 10
```
```r
#note that Sunday is accepted as the first day of the week
wday(womensday)
```
```
#> [1] 2
```
```r
wday(womensday, label=TRUE)
```
```
#> [1] Mon
#> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
```
```r
yday(womensday)
```
```
#> [1] 67
```
---
#### SET components of date-time
- `lubridate` can be used to not only extract but also **change** parts of date-time objects.
```r
month(womensday) <- 12
womensday
second(womensday) <- 99
womensday
# Use update function to change multiple values
womensday_up <- update(womensday, year = 1976, day = 16, month = 6, hour = 8)
womensday_up
```
---
- In `R`, we can get the current time by typing `Sys.time()`.
```r
Sys.time()
```
```
#> [1] "2021-11-14 18:25:39 +03"
```
```r
class(Sys.time())
```
```
#> [1] "POSIXct" "POSIXt"
```
- The `lubridate` package provides a slightly more advanced function, `now`, that permits you define the time zone:
```r
now()
```
```
#> [1] "2021-11-14 18:25:39 +03"
```
```r
#time in Turkey now
now("Turkey")
```
```
#> [1] "2021-11-14 18:25:39 +03"
```
```r
#time in US-Eastern cost now
now("US/Eastern")
```
```
#> [1] "2021-11-14 10:25:39 EST"
```
- You can see all the available times zones with the `OlsonNames()` function.
---
- The `lubridate` also has a function to extract hours, minutes and seconds:
```r
now() %>% hour()
```
```
#> [1] 18
```
```r
now() %>% minute()
```
```
#> [1] 25
```
```r
now() %>% second()
```
```
#> [1] 39.20986
```
---
- **Hands-on example:** Visit `01-lubridate_casestudy.Rmd` file.
<img src="images/garmin.png" width="80%" height="100%" />
---
class: middle, center
```
#> ππππππππππππππππππππππππππππππ
```
---
- More at:
- [Scale_date](https://ggplot2.tidyverse.org/reference/scale_date.html)
- [Lubridate](https://rstudio-pubs-static.s3.amazonaws.com/422499_dcc2ed60c639458ba349b21e22059ac9.html#chapter-2---parsing-dates-with-lubridate).
- [Dates and Times in R](https://www.stat.berkeley.edu/~s133/dates.html#:~:text=Dates%20stored%20in%20the%20POSIX,more%20accurate%20representation%20of%20times).
- [Missing Dates](https://blog.exploratory.io/populating-missing-dates-with-complete-and-fill-functions-in-r-and-exploratory-79f2a321e6b5).
- [Lubridate](https://wrangle-r.rsquaredacademy.com/lubridate.html).
---
# Attributions
- All images used in this slide are taken from the web.
- This lecture note is mainly developed by following sources:
- [Source 1](https://github.com/datasciencelabs/2020/blob/master/03_wrangling/05_dates-and-times.Rmd),
- [Source 2](https://eddatascienceees.github.io/tutorial-sian-phillips/), and
- [Source 3](https://github.com/MeganBeckett/lubridate-heatmaps_tutorial/blob/master/code/lubridate_tutorial.Rmd).
</textarea>
<style data-target="print-only">@media screen {.remark-slide-container{display:block;}.remark-slide-scaler{box-shadow:none;}}</style>
<script src="https://remarkjs.com/downloads/remark-latest.min.js"></script>
<script src="assets/remark-zoom.js"></script>
<script src="https://platform.twitter.com/widgets.js"></script>
<script>var slideshow = remark.create({
"highlightStyle": "github",
"highlightLines": true,
"countIncrementalSlides": false,
"ratio": "16:9",
"navigation": {
"scroll": false
}
});
if (window.HTMLWidgets) slideshow.on('afterShowSlide', function (slide) {
window.dispatchEvent(new Event('resize'));
});
(function(d) {
var s = d.createElement("style"), r = d.querySelector(".remark-slide-scaler");
if (!r) return;
s.type = "text/css"; s.innerHTML = "@page {size: " + r.style.width + " " + r.style.height +"; }";
d.head.appendChild(s);
})(document);
(function(d) {
var el = d.getElementsByClassName("remark-slides-area");
if (!el) return;
var slide, slides = slideshow.getSlides(), els = el[0].children;
for (var i = 1; i < slides.length; i++) {
slide = slides[i];
if (slide.properties.continued === "true" || slide.properties.count === "false") {
els[i - 1].className += ' has-continuation';
}
}
var s = d.createElement("style");
s.type = "text/css"; s.innerHTML = "@media print { .has-continuation { display: none; } }";
d.head.appendChild(s);
})(document);
// delete the temporary CSS (for displaying all slides initially) when the user
// starts to view slides
(function() {
var deleted = false;
slideshow.on('beforeShowSlide', function(slide) {
if (deleted) return;
var sheets = document.styleSheets, node;
for (var i = 0; i < sheets.length; i++) {
node = sheets[i].ownerNode;
if (node.dataset["target"] !== "print-only") continue;
node.parentNode.removeChild(node);
}
deleted = true;
});
})();
(function() {
"use strict"
// Replace <script> tags in slides area to make them executable
var scripts = document.querySelectorAll(
'.remark-slides-area .remark-slide-container script'
);
if (!scripts.length) return;
for (var i = 0; i < scripts.length; i++) {
var s = document.createElement('script');
var code = document.createTextNode(scripts[i].textContent);
s.appendChild(code);
var scriptAttrs = scripts[i].attributes;
for (var j = 0; j < scriptAttrs.length; j++) {
s.setAttribute(scriptAttrs[j].name, scriptAttrs[j].value);
}
scripts[i].parentElement.replaceChild(s, scripts[i]);
}
})();
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
// adds .remark-code-has-line-highlighted class to <pre> parent elements
// of code chunks containing highlighted lines with class .remark-code-line-highlighted
(function(d) {
const hlines = d.querySelectorAll('.remark-code-line-highlighted');
const preParents = [];
const findPreParent = function(line, p = 0) {
if (p > 1) return null; // traverse up no further than grandparent
const el = line.parentElement;
return el.tagName === "PRE" ? el : findPreParent(el, ++p);
};
for (let line of hlines) {
let pre = findPreParent(line);
if (pre && !preParents.includes(pre)) preParents.push(pre);
}
preParents.forEach(p => p.classList.add("remark-code-has-line-highlighted"));
})(document);</script>
<script>
slideshow._releaseMath = function(el) {
var i, text, code, codes = el.getElementsByTagName('code');
for (i = 0; i < codes.length;) {
code = codes[i];