在R中,我有一堆我在GMT中测量的日期时间值.我一直遇到一些事故,其中一些功能或其他功能失去了我的价值观的时区,甚至失去了班级名称.即使是如此基本的功能c()和unlist():
> dput(x)
structure(1317830532, class = c("POSIXct", "POSIXt"), tzone = "GMT")
> dput(c(x))
structure(1317830532, class = c("POSIXct", "POSIXt"))
> dput(list(x))
list(structure(1317830532, class = c("POSIXct", "POSIXt"), tzone = "GMT"))
> dput(unlist(list(x)))
1317830532
Run Code Online (Sandbox Code Playgroud)
如果这种情况发生在我最不想要的时候,我觉得我的头发远离真正的火星气候轨道器时刻.任何人都有任何策略,以确保他们的日期"保持"?
此行为记录在?c,?DateTimeClasses并且?unlist:
来自?DateTimeClasses:
使用
c"POSIXlt"对象将它们转换为当前时区,"POSIXct"对象将删除任何"tzone"属性(即使它们都标有相同的时区).*
来自?c:
c有时用于删除除名称之外的属性的副作用.*
也就是说,我的测试表明,尽管使用c或是,数据的完整性仍保持不变unlist.例如:
x <- structure(1317830532, class = c("POSIXct", "POSIXt"),
tzone = "GMT")
y <- structure(1317830532+3600, class = c("POSIXct", "POSIXt"),
tzone = "PST8PDT")
x
[1] "2011-10-05 16:02:12 GMT"
y
[1] "2011-10-05 10:02:12 PDT"
strftime(c(x, y), format="%Y/%m/%d %H:%M:%S", tz="GMT")
[1] "2011/10/05 16:02:12" "2011/10/05 17:02:12"
strftime(c(x, y), format="%Y/%m/%d %H:%M:%S", tz="PST8PDT")
[1] "2011/10/05 09:02:12" "2011/10/05 10:02:12"
strftime(unlist(y), format="%Y/%m/%d %H:%M:%S", tz="PST8PDT")
[1] "2011/10/05 10:02:12"
Run Code Online (Sandbox Code Playgroud)
如果您使用R来跟踪日期,您的火星漫游者应该没问题.