Hello, In one of my functions, I need to extract the hour from a date. For example: as.POSIXlt("2010-03-27 02:00:00")$hour gives 2 as expected. It works for all the dates I've tested except the following one which is in my list of dates: as.POSIXlt("2010-03-28 02:00:00")$hour which gives 0. I don't understand why it doesn't work with this particular date. Any idea ? Thanks in advance, Ptit Bleu (with R 2.9.0 under Windows ). -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-as-POSIXlt-hour-tp2255758p2255758.html Sent from the R help mailing list archive at Nabble.com.
On 15.06.2010 13:45, PtitBleu wrote:> > Hello, > > In one of my functions, I need to extract the hour from a date. > For example: > as.POSIXlt("2010-03-27 02:00:00")$hour gives 2 as expected. > It works for all the dates I've tested except the following one which is in > my list of dates: > as.POSIXlt("2010-03-28 02:00:00")$hour which gives 0.>> I don't understand why it doesn't work with this particular date. > > Any idea ? > > Thanks in advance, > Ptit Bleu (with R 2.9.0 under Windows ). >Perhaps it has been fixed within the last > 12 months since R-2.9.0 has been released? Please try a recent version of R. Uwe Ligges
On Jun 15, 2010, at 7:45 AM, PtitBleu wrote:> > Hello, > > In one of my functions, I need to extract the hour from a date. > For example: > as.POSIXlt("2010-03-27 02:00:00")$hour gives 2 as expected. > It works for all the dates I've tested except the following one > which is in > my list of dates: > as.POSIXlt("2010-03-28 02:00:00")$hour which gives 0. > > I don't understand why it doesn't work with this particular date.It "works" for me with a result of 2, so I suspect it has something to do with whether that hour even "exists" during the shift from "ordinary" time to daylight savings time in your LOCALE (which was not offered but would be plausibly near GMT/UMT given the domain from which you are posting).> > Any idea ? > > Thanks in advance, > Ptit Bleu (with R 2.9.0 under Windows ). ...... wrong info for this question, I suspect. -- David Winsemius, MD West Hartford, CT
Hello again, You are right: it corresponds to the DST time transition in France (I think you have guessed it was France from my "Frenglish" style - sorry about it). To get around this problem, I now use : as.numeric(format(strptime("2010-03-28 02:00:00", format="%Y-%m-%d %H:%M:%S"), format="%H")) Thanks again for your help. Ptit Bleu. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-as-POSIXlt-hour-tp2255758p2255997.html Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- Problem with long number (from character to numeric class)
- Homography with R
- looking for the RMySQL package for R 2.12.0 under XP
- executable R script under xp (to avoid migration toward Matlab or C++)
- looking for a package to solve current-voltage equation I=f(I)