joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
220 stars 71 forks source link

to.daily producing duplicates #277

Closed ggrothendieck closed 5 years ago

ggrothendieck commented 5 years ago

The code below results in duplicate date values in zd for 2015-10-23. to.daily should not have produced duplicates.

Lines <- "localminute,dataid,meter_value
2015-10-03 09:51:53,6578,157806
2015-10-13 13:41:49,6578,158086
2015-10-13 17:41:49,6578,158088
2015-10-13 20:40:49,6578,158100
2015-10-13 22:19:50,6578,158102
2015-10-15 18:41:48,6578,158170
2015-10-16 19:51:49,6578,158180
2015-10-18 22:16:48,6578,158202
2015-10-19 01:14:47,6578,158204
2015-10-19 01:20:47,6578,158204
2015-10-19 02:45:48,6578,158204
2015-10-19 17:49:48,6578,158210
2015-10-19 19:56:48,6578,158212
2015-10-19 20:14:47,6578,158212
2015-10-19 20:56:48,6578,158212
2015-10-19 23:34:47,6578,158212
2015-10-20 02:21:47,6578,158214
2015-10-20 21:46:48,6578,158222
2015-10-20 21:51:47,6578,158222
2015-10-20 22:19:47,6578,158222
2015-10-21 20:24:46,6578,158232
2015-10-22 21:50:46,6578,158262
2015-10-23 05:50:46,6578,158276
2015-10-23 07:16:46,6578,158276
2015-10-23 11:01:45,6578,158278
2015-10-23 11:11:46,6578,158278
2015-10-23 17:01:46,6578,158290
2015-10-24 04:31:46,6578,158300
2015-10-24 10:46:45,6578,158304
2015-10-24 23:19:46,6578,158314
2015-10-24 23:41:45,6578,158314"

library(xts)
library(zoo)
z <- read.csv.zoo(text = Lines)
zd <- to.daily(z)

giving:

> zd
           z.Open z.High z.Low z.Close
2015-10-03   6578   6578  6578    6578
2015-10-14   6578   6578  6578    6578
2015-10-15   6578   6578  6578    6578
2015-10-16   6578   6578  6578    6578
2015-10-19   6578   6578  6578    6578
2015-10-20   6578   6578  6578    6578
2015-10-21   6578   6578  6578    6578
2015-10-22   6578   6578  6578    6578
2015-10-23   6578   6578  6578    6578
2015-10-23   6578   6578  6578    6578
2015-10-25   6578   6578  6578    6578
joshuaulrich commented 5 years ago

Thanks for the report! I can replicate. This is ultimately caused by xts:::.drop.time() not accounting for the local timezone when converting to Date.

joshuaulrich commented 5 years ago

This also looks like it may be a duplicate of #53.

joshuaulrich commented 5 years ago

Closing because I verified this is a duplicate, and is now fixed.