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

Sandy Adriaenssens Sandy.Adriaenssens at UGent.be
Fri Jul 13 12:51:54 CEST 2012


Dear all,

I have dataset which contains date and time in the format
"yearmonthdayhour". I can read in these data correctly as follows:

mydata <- read.csv("pm10_corine_gridcel_hourly_2011.csv", header = TRUE)
mydata$date <- as.POSIXct(strptime(mydata$date, format = "%Y%m%d%H",
tz="UTC"))

However, midnight is defined as 24:00 in my original file (so the end of the
day), while the POSIXct function changes this to 0:00 (the beginning of the
next day).
So, my data now go from January 1 2011 1:00 to Januari 1 2012 0:00, in stead
of December 31 2011 24:00.

summary(mydata$date)
                 Min.               1st Qu.                Median 
"2011-01-01 01:00:00" "2011-04-02 06:45:00" "2011-07-02 12:30:00" 
                 Mean               3rd Qu.                  Max. 
"2011-07-02 12:30:00" "2011-10-01 18:15:00" "2012-01-01 00:00:00" 

I would like to change this 0:00 to 24:00 again since I want to include
these values in daily averages of the previous day (and not of the next
day). So the day of the month should also be diminished by 1.

I have tried extracting the hours which are 0 and converting them to 24, but
then I can't paste them back in the date/time of the original data.fram
again.

Are there maybe other solutions?

Thanks in advance,

Sandy

ifelse (as.POSIXlt(mydata[24,1])$hour = "0",as.POSIXlt(mydata[24,1])$hour =
"24" 


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



More information about the R-help mailing list