看起来这是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),并可能影响其他列。以下是使用
method="raw"
的示例。请注意,在两种情况下,我们都得到了
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")
编辑:添加了使用method = "raw"
的示例