For UK-format dates with month second, one of these dates is legit, but the other two make no sense.
Our data frame’s last column:
Back to this:
ddd
# A tibble: 3 × 3
date status dunno
<date> <chr> <chr>
1 2011-08-03 hello August 3 2011
2 2011-11-15 still here November 15 2011
3 2012-02-01 goodbye February 1 2012
Month, day, year in that order.
so interpret as such
(ddd %>%mutate(date2 =mdy(dunno)) -> d4)
Are they really the same?
Column date2 was correctly converted from column dunno:
d4 %>%mutate(equal =identical(date, date2))
# A tibble: 3 × 5
date status dunno date2 equal
<date> <chr> <chr> <date> <lgl>
1 2011-08-03 hello August 3 2011 2011-08-03 TRUE
2 2011-11-15 still here November 15 2011 2011-11-15 TRUE
3 2012-02-01 goodbye February 1 2012 2012-02-01 TRUE
unite glues things together with an underscore between them (if you don’t specify anything else). Syntax: first thing is new column to be created, other columns are what to make it out of.
unite makes the original variable columns year, month, day disappear.
We may need to calculate the time between two events. For example, these are the dates and times that some patients were admitted to and discharged from a hospital:
Comments
days(1)
,months(1)
etc.