class: title-slide, center, bottom <img src="images/lubridate_hex.png" width="100" /> # Using lubridate to<br/>work with time intervals ## RStudio Instructor Certification Teaching Exam ### Silvia Canelón, PhD ### September 17th, 2020 --- 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 ###
All Nobel laureates (i.e. date of birth, date of death) -- ###
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[
Goal] Calculate laureate's age at the time of the award ] .right-column[ ![:scale 90%](images/RIT_lubridate_ex1-1.png) ] --- .left-column[ ### .bold[
Goal] Calculate laureate's age at the time of the award ] .right-column[ ![:scale 90%](images/RIT_lubridate_ex1-2.png) ] --- #
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` -- ##
Correct answers: c and d --- class: title-slide, center, middle # Let's go live! ##
--- 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[
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[
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[
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[
Goal] Determine if the prize was awarded during the laureate's lifetime ] .right-column[ ![:scale 90%](images/RIT_lubridate_ex2-3.png) ] --- #
Knowledge check ## How would we complete the following? ```r nobel_laureates %>% mutate(new_variable = * ifelse(prize_date %within% _______(start_point, end_point), 1, 0)) ``` -- ##
Correct answer: ```r 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! ##
--- class: title-slide, center, middle # Fin. ## Thank you! ##