在我的机器上,sqldf将POSIXct从本地时间(我在CST,GMT-0600)更改为GMT/UTC。这是预期的行为吗?我可以阻止R或sqldf执行此操作吗?这是我的代码:
> library('sqldf')
>
> before <- data.frame(ct_sys = Sys.time())
> before
ct_sys
1 2012-03-01 12:57:58
> after <- sqldf('select * from before')
> after
ct_sys
1 2012-03-01 18:57:58
>
这似乎是sqldf中的一个时区错误。它现在应该在sqldf版本0.4-6.2中得到修复(还没有在CRAN上,但你可以这样尝试):
library(sqldf)
source("http://sqldf.googlecode.com/svn/trunk/R/sqldf.R")
before <- data.frame(ct_sys = Sys.time()); before
after <- sqldf('select * from before'); after
即使不这样做,sqldf("select * from before", method = "raw")
也会起作用,尽管这将返回一个数字列(您可以将其转换为POSIXct),并且可能还会影响其他列。以下是使用CCD_ 2的示例。注意,在这两种情况下,我们都得到1330661786.181
:
> library(sqldf)
>
> before <- data.frame(ct_sys = Sys.time()); dput(before)
structure(list(ct_sys = structure(1330661786.181, class = c("POSIXct",
"POSIXt"))), .Names = "ct_sys", row.names = c(NA, -1L), class = "data.frame")
>
> after <- sqldf('select * from before', method = "raw"); dput(after)
structure(list(ct_sys = 1330661786.181), .Names = "ct_sys", row.names = 1L, class = "data.frame")
EDIT:添加了使用method = "raw"
的示例