0

R supports time from 00:00 to 23:59. Is there a way to change it to 24:00. creating a POSIXct object of "2012-12-03 24:00" makes it "2012-12-04 00:00". For my dataset(TMY3) this is problematic.

As a workaround I have replaced all instance of "24:00" with "23:59" and then convert to POSIXct. The problem now is that I cannot use helper functions to extract just the hour. 23:50 and 23:00 both are 23hr. plotting points by hour now have two datapoints at 23hr.

What are my options?

MySchizoBuddy
  • 1,138
  • 13
  • 20
  • 3
    You should post the "dataset" in whatever form you are working with. If it's a text file, then post enough of that to illustrate the problem along with the input code you are currently using. And then explain what the "problem" is. Midnght is midnight, and the convention is that midnight is the beginning of the next day. So exactly what is the problem? – IRTFM Jul 19 '15 at 20:06
  • 1
    I suspect you'll have to define it with a new parent class (`POSIX24ct` for example) and write a `format.POSIX24ct` that has the logic to print 24:00 instead of 00:00. Do you also want 00:01 to be 24:01 and so on? – Spacedman Jul 19 '15 at 20:23

1 Answers1

0

The simple answer is that you can't really do this. You could certainly make a function to print a POSIXct object as the previous day with a 24 instead of a 0 but what you're asking is the equivalent to asking "Can I make 50 (fifty) show up as 40_10 (forty-ten)?"

Depending on what you'd really like to do you could do something like ifelse(hour(POSobj)==0,24,hour(POSobj)) (you've tagged lubridate so I assume those functions are fair game) or you could do the following as well...

ifelse(hour(POSobj)==0,gsub(" 00:"," 24:",gsub(as.character(floor_date(POSobj)),as.character(floor_date(POSobj)-days(1)),POSobj)),as.character(POSobj))

Dean MacGregor
  • 11,847
  • 9
  • 34
  • 72