Re: [R] read mignight as 24:00 and not as 0:00
Ok, thank you Dan! I was already afraid that I would get this answer. I will solve it by defining date/time both as a date/time object and as a character object ( in another column) Regards, Sandy -- View this message in context: http://r.789695.n4.nabble.com/read-mignight-as-24-00-and-not-as-0-00-tp4636423p4636884.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read mignight as 24:00 and not as 0:00
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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read mignight as 24:00 and not as 0:00
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Sandy Adriaenssens Sent: Monday, July 16, 2012 8:10 AM To: r-help@r-project.org Subject: Re: [R] read mignight as 24:00 and not as 0:00 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 Sandy, It is not possible to do you want in the way that you want, i.e. using R date/time values, because midnight is the beginning of a new day and not the end of a day. The time 24:00 does not exist in all the time keeping systems that I am aware of. If you want use R date/time objects, then I would read the data, subtract 1 hour from the value read, and reconceptualize your analyses as time representing when the hour of interest began, rather than when it ended. You can always keep the text representation of the date/time if you wish to present your analyses in the 1:00 to 24:00 format. Or as someone else suggested, you extract the hour as a separate object represented as 1 to 24. Sorry I can't be of much more help, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] read mignight as 24:00 and not as 0:00
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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read mignight as 24:00 and not as 0:00
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sandy Adriaenssens Sent: Friday, July 13, 2012 3:52 AM To: r-help@r-project.org Subject: [R] read mignight as 24:00 and not as 0:00 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 Sandy, You really haven't given us enough information to provide a solution, but here are some questions and suggestions. Do you have any times less than 01:00:00 ? You mention going from 01:00:00 to 24:00:00 in you data. I presume these are text fields and not time objects. Do you have fractional hours represented in your data, or are all times on the hour? 1. If your times are always on the hour no minutes or second, i.e. 01:00 to 24:00, then you could read them as is and then just subtract 1 hour from all date/time values. 2. If you have fractional hours, e.g. 00:32:00 or 11:45, then you could possible just read the date/time values and whenever the time is exactly 00:00:00, subtract 1 second from the value. this will at least get you just before midnight on the previous day. Whether either of these approaches will work for you depends on what your actual needs are. If this doesn't work for you, you will need to write back to R-help and explain more about what your actual needs are, and and provide more detail about you actual dates and times (see questions above. Hope this is somewhat helpful, Dan Daniel Nordlund Bothell, WA USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] read mignight as 24:00 and not as 0:00
Extract the date separately from the time initially, and keep it separate. When you want to process daily data, use that column. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Daniel Nordlund djnordl...@frontier.com wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sandy Adriaenssens Sent: Friday, July 13, 2012 3:52 AM To: r-help@r-project.org Subject: [R] read mignight as 24:00 and not as 0:00 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 Sandy, You really haven't given us enough information to provide a solution, but here are some questions and suggestions. Do you have any times less than 01:00:00 ? You mention going from 01:00:00 to 24:00:00 in you data. I presume these are text fields and not time objects. Do you have fractional hours represented in your data, or are all times on the hour? 1. If your times are always on the hour no minutes or second, i.e. 01:00 to 24:00, then you could read them as is and then just subtract 1 hour from all date/time values. 2. If you have fractional hours, e.g. 00:32:00 or 11:45, then you could possible just read the date/time values and whenever the time is exactly 00:00:00, subtract 1 second from the value. this will at least get you just before midnight on the previous day. Whether either of these approaches will work for you depends on what your actual needs are. If this doesn't work for you, you will need to write back to R-help and explain more about what your actual needs are, and and provide more detail about you actual dates and times (see questions above. Hope this is somewhat helpful, Dan Daniel Nordlund Bothell, WA USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.