Convert the following to date or date/time objects.
## [1] "2010-09-13"
## [1] "2010-09-13"
## [1] "2010-09-13"
mdy("S 13, 2010")
## [1] NA
date <- c("S 13, 2010")
date %>%
str_replace("S", "Sep") %>%
mdy()
## [1] "2010-09-13"
“S” does not seem to be enough information for lubridate.
## [1] "1941-12-07"
## [1] "1998-05-01"
## [1] "1998-01-05"
It isn’t clear which single-digit number represents the month, and which represents the day.
## [1] "1998-05-21"
There are not 21 months in a year, which means “21” must represent the day.
## [1] "2020-05-05 10:30:00 UTC"
## [1] "2020-05-05 10:30:00 PDT"
## [1] "2020-05-05 10:30:00 AST"
Using just your date of birth (ex: Sep 7, 1998) and today’s date, calculate the following. (Write your code in a manner that the code will work on any date after you were born.)
## [1] "2059-06-09"
## [1] 26
## [1] "2021-06-09"
## [1] "105d 0H 0M 0S"
## [1] "3m 16d 0H 0M 0S"
Suppose you have arranged for a phone call to be at 3 pm on May 8, 2015 at Arizona time. However, the recipient will be in Auckland, NZ. What time will it be there?
## [1] "2015-05-09 10:00:00 NZST"
From this book’s GitHub directory, navigate to the data-raw directory and then download the Pulliam_Airport_Weather_Station.csv data file. (There are several weather station files. Make sure you get the correct one!) There is a DATE column (is it of type date when you import the data?) as well as the Maximum and Minimum temperature. For the last 5 years of data we have (exactly, not just starting at Jan 1, 2014!), plot the time series of daily maximum temperature with date on the x-axis. Write your code so that it will work if I update the data set. Hint: Find the maximum date in the data set and then subtract 5 years. Will there be a difference if you use dyears(5) vs years(5)? Which seems more appropriate here?
It turns out there is some interesting periodicity regarding the number of births on particular days of the year.
data(Births78, package="mosaicData")
births <- Births78 %>%
select(c("date", "births"))
Clearly there are some days that have many more births than other days, though it’s hard to determine exactly which days of the week follow which trend from this graph. I’m wondering if it has to do with the dates/times people schedule c-sections for, depending on what proportion of births are c-sections?
births <- births %>%
mutate(dow = wday(date, label=TRUE))
It does look like there are fewer births on the weekends, generally, which may have to do with hospital scheduling!