It's due to the conversion:
table(is.na(t))
# FALSE TRUE
#183956 21
time[is.na(t),]
# A tibble: 21 x 1
# datetime
# <chr>
# 1 2030-03-1002:00:00
# 2 2031-03-0902:00:00
# 3 2032-03-1402:00:00
# 4 2033-03-1302:00:00
# 5 2034-03-1202:00:00
# 6 2035-03-1102:00:00
# 7 2036-03-0902:00:00
# 8 2037-03-0802:00:00
# 9 2038-03-1402:00:00
#10 2039-03-1302:00:00
# ... with 11 more rows
Not sure why, I suspect this has to do with timezone switching:
as.POSIXct("2039-03-13 02:00:00", format="%Y-%m-%d %H:%M:%S")
# [1] NA
as.POSIXct("2039-03-13 01:00:00", format="%Y-%m-%d %H:%M:%S")
# [1] "2039-03-13 01:00:00 EST"
as.POSIXct("2039-03-13 03:00:00", format="%Y-%m-%d %H:%M:%S")
# [1] "2039-03-13 03:00:00 EDT"
The package lubridate tends to be more robust to these things:
library(lubridate)
time <- time %>%
mutate(converted_POSIXct = as.POSIXct(datetime, format="%Y-%m-%d %H:%M:%S"),
converted_dt = as_datatime(datetime)) %>%
arrange(converted_dt)
table(is.na(time$converted_POSIXct))
# FALSE TRUE
#183956 21
table(is.na(time$converted_dt))
# FALSE
#183977