Here is some code illustrating a behavior I don't love:
library(tidyverse)
> df <- data.frame(
+ the_date=c(as.Date("2021-01-01"), as.Date("2021-01-02")),
+ keep=c(T, T))
> df %>% summarize(the_min=min(the_date))
the_min
1 2021-01-01
> df %>% summarize(the_min=min(ifelse(keep, the_date, NA)))
the_min
1 18628
> df %>% summarize(the_min=as.Date(min(the_date), origin="1970-01-01"))
the_min
1 2021-01-01
In the third case, the minimum of the dates is returned as 18628, whereas I'd like it to be a Date that is 2021-01-01
. As shown, I can add back the as.Date
with an origin of 1970-01-01
, but do I have to?
P.S. It's tidyverse
1.3.0.
P.P.S. This seems related to Date shows up as number.