I have long dataframe as below (Note: DoY: Day of the Year, Hour: Hour of the Day (e.g., Hour =0.5 means 12:30 AM):
Year DoY Hour
2016 126 0.5
2016 126 1
2016 126 1.5
- - -
2016 127 0
2016 127 0.5
- - -
2018 300 23.5
- - -
I am trying to combine these columns to single DateTime column (e.g. 2016-05-05 12:30 AM, 2016-05-05 1:00 AM, etc.). I tried following code:
x <- as.numeric(df$Hour)
x.m <- paste(floor(x), round((x-floor(x))*60), sep=":")
df$HourMinute <- x.m
df$DateTime <- strptime(paste0(df$Year, df$DoY, df$HourMinute), format = "%Y%j%H:%M")
Above code results into some strange output. After a Year end, It outputs NA values. How to create the desired output column?