-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlubridate_slides.Rmd
206 lines (150 loc) · 4.57 KB
/
lubridate_slides.Rmd
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
---
title: "Using lubridate to<br/>work with time intervals"
subtitle: "RStudio Instructor Certification Teaching Exam"
author: "Silvia Canelón, PhD"
institute: "@spcanelon"
date: "September 17th, 2020"
output:
xaringan::moon_reader:
css: ["default", "rit-spc.css", "rit-fonts-spc.css"]
lib_dir: libs
seal: false
nature:
beforeInit: "macros.js"
highlightStyle: github
highlightLines: true
highlightLanguage: ["r", "css", "yaml"]
countIncrementalSlides: true
ratio: "16:9"
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
knitr::opts_chunk$set(collapse = TRUE,
fig.retina = 3,
warning = FALSE,
message = FALSE)
library(tidyverse)
library(lubridate)
library(xaringanExtra)
xaringanExtra::use_xaringan_extra(include = c("panelset", "tile_view", "share_again", "use_broadcast"))
xaringanExtra::style_share_again(share_buttons = c("twitter", "linkedin", "pocket"))
xaringanExtra::embed_xaringan(
url = "https://spcanelon.github.io/rit-teaching-exam", ratio = "16:9")
```
class: title-slide, center, bottom
```{r, echo=FALSE, out.width=100}
knitr::include_graphics("images/lubridate_hex.png")
```
# `r rmarkdown::metadata$title`
## `r rmarkdown::metadata$subtitle`
### `r rmarkdown::metadata$author`
### `r rmarkdown::metadata$date`
---
class: left, middle
# Today: Time spans in lubridate
.center[
![:scale 90%](images/lubridate_timespans.png)
]
---
class: left, middle
# This lesson: intervals
.center[
![:scale 90%](images/lubridate_timespans_intervals.png)
]
---
class: left, middle
# The dataset contains information about
### `r icon::fa("user-friends")` All Nobel laureates (i.e. date of birth, date of death)
--
### `r icon::fa("award")` The Nobel Prize Award (i.e. year of the award)
--
### Originally prepared by [Kaggle](https://www.kaggle.com/nobelfoundation/nobel-laureates#archive.csv) and then<br/>made available for [TidyTuesday on 2019-05-14](https://github.com/rfordatascience/tidytuesday/blob/3040e14f3b4934e6fc621f57d78324b53e549086/data/2019/2019-05-14/readme.md)
---
class: inverse, center, middle
# Examples
## 1. .bold[Calculate laureate's age at the time of the award]
## 2. Determine if the prize was awarded<br/>during the laureate's lifetime
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Calculate laureate's age at the time of the award
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex1-1.png)
]
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Calculate laureate's age at the time of the award
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex1-2.png)
]
---
# `r icon::fa("brain")` Knowledge check
## Which of these could we use to find a time interval?
### a. `interval(start_point) - interval(end_point)`
### b. `start_point - end_point`
### c. `interval(start_point, end_point)`
### d. `start_point %--% end_point`
--
## `r icon::fa("check-square")` Correct answers: c and d
---
class: title-slide, center, middle
# Let's go live!
## `r icon::fa("code")`
---
class: inverse, center, middle
# Examples
## 1. Calculate laureate's age at the time of the award
## 2. .bold[Determine if the prize was awarded<br/>during the laureate's lifetime]
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Determine if the prize was awarded during the laureate's lifetime
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex1-2.png)
]
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Determine if the prize was awarded during the laureate's lifetime
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex2-1.png)
]
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Determine if the prize was awarded during the laureate's lifetime
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex2-2.png)
]
---
.left-column[
### .bold[`r icon::fa("lightbulb")` Goal] Determine if the prize was awarded during the laureate's lifetime
]
.right-column[
![:scale 90%](images/RIT_lubridate_ex2-3.png)
]
---
# `r icon::fa("brain")` Knowledge check
## How would we complete the following?
```{r eval=FALSE}
nobel_laureates %>%
mutate(new_variable =
ifelse(prize_date %within% _______(start_point, end_point), 1, 0)) #<<
```
--
## `r icon::fa("check-square")` Correct answer:
```{r eval=FALSE}
nobel_laureates %>%
mutate(new_variable =
ifelse(prize_date %within% interval(start_point, end_point), 1, 0))
```
---
class: title-slide, center, middle
# Let's go live!
## `r icon::fa("code")`
---
class: title-slide, center, middle
# Fin.
## Thank you!
## `r icon::fa("chalkboard-teacher")`