Code along...https://rstudio.cloud/project/1817769
Slides...https://jennyslides.netlify.app/lubridate/
🐦 @allisonhorst
The best thing about open source software like R is that there are SO many learning resources.
The best worst thing about open source software like R is that there are SO many learning resources.
The best worst thing about open source software like R is that there are SO many learning resources.
tutorial = learning oriented, lessons that take the reader by the hand through a series of steps to complete a project/exercise, show the beginner can achieve something meaningful
how to guide = problem oriented, guides that take the reader through the steps required to solve a common problem, recipes/directions to do something specific
reference = technical descriptions of the machinery and how to operate it
discussion = explanations that clarify and illuminate a particular topic, background, context, explain why things are the way they are.
skip tutorials and go straight to "how to" guides
image credit: https://documentation.divio.com/introduction/
year()
, month()
, wday()
🐦 @juliasilge
Find a cool dataset and copy Julia.
dataset = COVID testing rates NSW
SMH: Sept 15 2020
Use date components within group_by()
+ summarise()
or within ggplot()
using...
year()
month()
day()
wday()
If your dates are in a consistent format, you can use...
ymd()
mdy()
dmy()
... to convert characters to dates
Why did the covid testing data parse as dates...
Why did the covid testing data parse as dates...
... but the Taylor/Beyonce data did not?
sales <- read_csv(here::here("data", "sales.csv"))sales$released[[1]]
## [1] "October 24, 2006"
tests <- read_csv(here::here("data", "totaltests.csv"))tests$test_date[[1]]
## [1] "2020-03-09"
Dates that are in year-month-day format (ISO 8601) will always parse as dates
google form: enter your birthday 3 times
diff_dates <- read_csv(here::here("data", "diffdatedata.csv")) %>% select(free_date)head(diff_dates)
## # A tibble: 6 × 1## free_date ## <chr> ## 1 30 June 1978 ## 2 17 Feb, 2011 ## 3 March 25 2014## 4 1977/7/11 ## 5 4 Sep 1981 ## 6 11/7/1987
dmy()
ymd()
mdy()
And parse_date_time()
is your friend...
diff_dates <- diff_dates %>% mutate(free_date_parsed = parse_date_time(free_date, c("ymd", "mdy", "dmy")))head(diff_dates, 8)
## # A tibble: 8 × 2## free_date free_date_parsed ## <chr> <dttm> ## 1 30 June 1978 1978-06-30 00:00:00## 2 17 Feb, 2011 2011-02-17 00:00:00## 3 March 25 2014 2014-03-25 00:00:00## 4 1977/7/11 1977-07-11 00:00:00## 5 4 Sep 1981 1981-09-04 00:00:00## 6 11/7/1987 1987-07-11 00:00:00## 7 sep 11 77 1977-09-11 00:00:00## 8 6th july 67 2067-07-06 00:00:00
diff_dates <- diff_dates %>% mutate(free_date_parsed = parse_date_time(free_date, c("ymd", "mdy", "dmy")))head(diff_dates, 8)
## # A tibble: 8 × 2## free_date free_date_parsed ## <chr> <dttm> ## 1 30 June 1978 1978-06-30 00:00:00## 2 17 Feb, 2011 2011-02-17 00:00:00## 3 March 25 2014 2014-03-25 00:00:00## 4 1977/7/11 1977-07-11 00:00:00## 5 4 Sep 1981 1981-09-04 00:00:00## 6 11/7/1987 1987-07-11 00:00:00## 7 sep 11 77 1977-09-11 00:00:00## 8 6th july 67 2067-07-06 00:00:00
parse_date_time()
failed to parse when there was no year.
it made an error when the year was only 2 digits.
Lubridate is full of functions that make working with dates in R easier
day()
, wday()
, month()
, year()
Lubridate is full of functions that make working with dates in R easier
Use date components in ggplot with...
day()
, wday()
, month()
, year()
Convert characters to dates with...
dmy()
, mdy()
, ymd()
Lubridate is full of functions that make working with dates in R easier
Use date components in ggplot with...
day()
, wday()
, month()
, year()
Convert characters to dates with...
dmy()
, mdy()
, ymd()
Whether R will recognise your dates depends on
Lubridate is full of functions that make working with dates in R easier
Use date components in ggplot with...
day()
, wday()
, month()
, year()
Convert characters to dates with...
dmy()
, mdy()
, ymd()
Whether R will recognise your dates depends on
BUT parse_date_time()
does a pretty good job 😄
Code along...https://rstudio.cloud/project/1817769
Slides...https://jennyslides.netlify.app/lubridate/
🐦 @allisonhorst
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |