library(data.table)
DateTime<-as.POSIXct(c("2025-05-16 00:00:02 CDT", "2025-05-16 00:00:03 CDT", "2025-05-16 00:00:06 CDT", "2025-05-16 00:00:07 CDT"))
TimeOfDay<-as.ITime(DateTime)
Year<-year(DateTime)
data.frame(DateTime,TimeOfDay,Year)
Gives the result:
DateTime V1 Year
1 2025-05-16 00:00:02 00:00:02 2025
2 2025-05-16 00:00:03 00:00:03 2025
3 2025-05-16 00:00:06 00:00:06 2025
4 2025-05-16 00:00:07 00:00:07 2025
Why is the second column named 'V1' and not TimeOfDay?
I can set the name separately, but I am curious why it happens with ITime column only. I have tried factors, numeric etc as columns and they work fine. I am using R 4.3.3
?as.ITimenotes in the first line of the Description that it is "Still experimental!" (as of data.table 1.14.8) so maybe not extensively tested to avoid weird behavior like that.data.table(DateTime,TimeOfDay,Year) |> as.data.frame().