I am trying to convert time in HH:MM:SS to date as YYYY-MM-DD in R accounting for midnight.
Time spans from morning in day 1 to morning in day 2, but I wanted to create a new column with a specific date in which time after midnight would indicate a new day. Here's an example:
Current data:
structure(list(ID = c("ID_002", "ID_002", "ID_002", "ID_002",
"ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002",
"ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002",
"ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002", "ID_002",
"ID_002", "ID_002", "ID_002", "ID_002"), Time = c("05:01:00",
"06:01:00", "07:01:00", "08:01:00", "09:01:00", "10:01:00", "11:01:00",
"12:01:00", "13:01:00", "14:01:00", "15:01:00", "16:01:00", "17:01:00",
"18:01:00", "19:01:00", "20:01:00", "21:01:00", "22:01:00", "23:01:00",
"00:01:00", "01:01:00", "02:01:00", "03:01:00", "04:01:00", "05:01:00",
"06:01:00", "07:01:00", "08:01:00", "09:01:00")), row.names = c(NA,
29L), class = "data.frame")
Desired output:
ID Time Date
ID_001 08:01:00 2021-01-20
ID_001 10:01:00 2021-01-20
ID_001 12:01:00 2021-01-20
ID_001 14:01:00 2021-01-20
ID_001 16:01:00 2021-01-20
ID_001 18:01:00 2021-01-20
ID_001 20:01:00 2021-01-20
ID_001 22:01:00 2021-01-20
ID_001 00:01:00 2021-01-21
ID_001 02:01:00 2021-01-21
ID_001 04:01:00 2021-01-21
ID_001 06:01:00 2021-01-21
ID_001 08:01:00 2021-01-21
Thanks for your help!