[datatable-help] Automagic timezone convertion on data.table rbind
Nicolas Chapados
nicolas.chapados at gmail.com
Tue Aug 31 21:40:20 CEST 2010
Dear list,
I'm using a data.table that contains date columns (in POSIXct format).
There appears to be an issue with automatic timezone conversion when
rbinding from NULL (or an empty data.table), as would occur when one is
progressively building up the table in a loop.
For example:
> require(data.table)
Loading required package: data.table
## Currently located in the North-America Eastern Standard Time zone.
> Sys.timezone()
[1] "America/Montreal"
> a <- NULL
## Create a table with a single date column (GMT timezone)
> b <- data.table(x = seq(as.POSIXct("2010-01-01", "GMT"),
as.POSIXct("2010-01-10", "GMT"), length.out=10))
> b
x
[1,] 2010-01-01
[2,] 2010-01-02
[3,] 2010-01-03
[4,] 2010-01-04
[5,] 2010-01-05
[6,] 2010-01-06
[7,] 2010-01-07
[8,] 2010-01-08
[9,] 2010-01-09
[10,] 2010-01-10
## Bind it from NULL: Oops! The timezone changes to EST!
> rbind(a,b)
x
[1,] 2009-12-31 19:00:00
[2,] 2010-01-01 19:00:00
[3,] 2010-01-02 19:00:00
[4,] 2010-01-03 19:00:00
[5,] 2010-01-04 19:00:00
[6,] 2010-01-05 19:00:00
[7,] 2010-01-06 19:00:00
[8,] 2010-01-07 19:00:00
[9,] 2010-01-08 19:00:00
[10,] 2010-01-09 19:00:00
## Same behavior from an empty data table.
> rbind(data.table(), b)
x
[1,] 2009-12-31 19:00:00
[2,] 2010-01-01 19:00:00
[3,] 2010-01-02 19:00:00
[4,] 2010-01-03 19:00:00
[5,] 2010-01-04 19:00:00
[6,] 2010-01-05 19:00:00
[7,] 2010-01-06 19:00:00
[8,] 2010-01-07 19:00:00
[9,] 2010-01-08 19:00:00
[10,] 2010-01-09 19:00:00
This behavior is somewhat puzzling. Any pointers as to how to preserve
timezone information would be greatly appreciated! For the record, I'm
with R version 2.9.2 and time.date version 1.4.1 (the latest on CRAN).
Best regards,
+ Nicolas Chapados
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20100831/dbca043d/attachment.htm>
More information about the datatable-help
mailing list