[R] probable timezone confusion with as.yearmon
Peter Keller
kellerp.l at gmail.com
Thu Mar 18 19:20:32 CET 2010
It looks like a timezone issue, and it's causing confusion to me at least.
My original data:
gmt <-
c("19880101 0000", "19880101 0100", "19880101 0300", "19880101 0400",
"19880101 0500", "19880101 0600")
These were converted to local dates/times with
akst<-strptime(gmt,format="%Y%m%d %H%M")-(3600*9) # because I want
local standard, not daylight savings time.
> dput(akst)
structure(c(567993600, 567997200, 568004400, 568008000, 568011600,
568015200), class = c("POSIXt", "POSIXct"), tzone = "")
Which looks like this on my system:
> akst
[1] "1987-12-31 15:00:00 AKST" "1987-12-31 16:00:00 AKST" "1987-12-31
18:00:00 AKST"
[4] "1987-12-31 19:00:00 AKST" "1987-12-31 20:00:00 AKST" "1987-12-31
21:00:00 AKST"
but why does this happen?
z<-as.yearmon(akst); z
[1] "Jan 1988" "Jan 1988" "Jan 1988" "Jan 1988" "Jan 1988" "Jan 1988"
I would expect this:
[1] "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987"
which I can get to by doing this:
z<-as.yearmon(akst-(3600*9)); z
[1] "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987" "Dec 1987"
But I don't understand why the first one doesn't give the answer I
expect (and would like).
Thanks for any help-
Peter
> sessionInfo()
R version 2.10.1 Patched (2010-03-16 r51294)
i386-pc-mingw32
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] zoo_1.6-2
loaded via a namespace (and not attached):
[1] grid_2.10.1 lattice_0.18-3 tools_2.10.1
> Sys.timezone()
[1] "AKDT"
More information about the R-help
mailing list