clair.crossupton at googlemail.com
2009-Oct-21 14:51 UTC
[R] date conversion not as i would have expected
Good day, i imported some data into R from Excel. By using the edit() function, this is what one of the dates looks like in R:> x <- structure(1254351600, class = c("POSIXt", "POSIXct"), tzone = "")[1] "2009-10-01 BST" However, when i do the following, the date changes:> as.Date(x, formate="%Y-%m-%d" )[1] "2009-09-30" I don't understand why this is happening. I realise that i can get around this by doing as.Date(as.character(x)), but would be nice to understand why it doesn't work directly. C xx
Hi This is on WinXP with regional settings as EST (we are now on DST but I run EST) R2.9.2 x <- structure(1254351600, class = c("POSIXt", "POSIXct"), tzone = "") > x [1] "2009-10-01 09:00:00 EST" > as.POSIXlt(x) [1] "2009-10-01 09:00:00 EST" > as.Date(x, formate="%Y-%m-%d" ) [1] "2009-09-30" I had a similar problem last week. I am not sure how Bill Gates does his times but for R see Rnews 4(1). There are slight differences between POSIX and Date classes NB If you run EST in DST periods Bill Gates still gives the file stamp as DST in Vista and XP. I would presume that it is the same for other zones where there is summer time zones Regards Duncan Mackay Department of Agronomy and Soil Science University of New England ARMIDALE NSW 2351 Email: home: macka at northnet.com.au At 00:51 22/10/2009, you wrote:>Good day, i imported some data into R from Excel. By using the edit() >function, this is what one of the dates looks like in R: > > > x <- structure(1254351600, class = c("POSIXt", "POSIXct"), tzone = "") >[1] "2009-10-01 BST" > >However, when i do the following, the date changes: > > > as.Date(x, formate="%Y-%m-%d" ) >[1] "2009-09-30" > >I don't understand why this is happening. I realise that i can get >around this by doing as.Date(as.character(x)), but would be nice to >understand why it doesn't work directly. > >C xx > >______________________________________________ >R-help at 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.