[R] read mignight as 24:00 and not as 0:00

Sandy Adriaenssens Sandy.Adriaenssens at UGent.be
Mon Jul 16 17:10:12 CEST 2012


Hi Dan,

Thank you for your answer. I 'll try to provide some more information:

I have only hourly data that go from 1:00:00 to 24:00:00, no minutes or
seconds. These data represent the average of measured valuesof the previous
hour (so 1:00:00 is the average of 0:00:00 to 1:00:00 data).  
I can indeed substract 1 hour from all date/time values to solve the
problem. However, I would also like to look at hourly variation within a day 
and then you always need to take into account the difference of 1 hour,
which will get confusing.

So, the easiest would be to convert all 0:00 values to 24:00 and set the
date one day back.

z.dr <- data.frame(times=c(seq.POSIXt(ISOdate(2011,1,1), ISOdate(2011,1,31),
by ="hour" )))

This generates a date/time serie looking like mine but shorter. Then I tried
converting all 0:00 to 24:00 values by the following loop:

for(i in nrow(z.dr))   {
	z.dr$times[i] <- ifelse(as.numeric(format(z.dr$times[i], "%H"))=="0",
		z.dr$times[i]+86400, z.dr$times[i])
}

However, here I get the error "Error in as.POSIXct.numeric(value) : 'origin'
must be supplied". Without the loop it works, but the output is a numerical
value.  
This is also not a good solution because the day is not changed by this
command.

Or is this just not possible to change?

Regards,
Sandy









--
View this message in context: http://r.789695.n4.nabble.com/read-mignight-as-24-00-and-not-as-0-00-tp4636423p4636651.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list