Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #2577] time-based to Date-based index causes 'duplicate' index values #53

Closed
joshuaulrich opened this issue Feb 26, 2015 · 0 comments
Assignees
Labels
Milestone

Comments

@joshuaulrich
Copy link
Owner

joshuaulrich commented Feb 26, 2015

Submitted by: Joshua Ulrich
Assigned to: Jeff Ryan
R-Forge link

From an email exchange with Garrett See:

I think going from time-based to date-based is common practice and should be supported. However, I probably don't fully appreciate the problem.

Perhaps a better illustration is to.daily() which already returns an object indexed by Date, but that object has an indexTZ:

set.seed(21)
systime <- as.POSIXct('2013-02-05 01:01', tz='America/Chicago')
x <- xts(rnorm(10000), systime-10000:1*60)
(D <- to.daily(x))
indexClass(D) # Date
indexTZ(D) # 'America/Chicago'
D  # 02/05 appears twice

Followups:

Date: 2013-02-24 03:38
Sender: Jeff Ryan
Note that this is really an R issue, though one that I would of course like to mask with xts.

> as.Date(format(index(to.period(x,'days'))))
[1] '2013-01-29' '2013-01-30' '2013-01-31' '2013-02-01' '2013-02-02'
[6] '2013-02-03' '2013-02-04' '2013-02-05'
> as.Date((index(to.period(x,'days'))))
[1] '2013-01-30' '2013-01-31' '2013-02-01' '2013-02-02' '2013-02-03'
[6] '2013-02-04' '2013-02-05' '2013-02-05'

.drop.time should probably use the format() approach to assure the avoidance of Dates in R as converted from POSIXct.


Date: 2013-03-02 17:43
Sender: Garrett See
Would it suffice to have to.period just provide the timezone when converting the index to Date.?

R> as.Date(index(to.period(x, 'days')), origin='1970-01-01', tz='America/Chicago')
[1] "2013-01-29" "2013-01-30" "2013-01-31" "2013-02-01" "2013-02-02"
[6] "2013-02-03" "2013-02-04" "2013-02-05"
joshuaulrich added a commit that referenced this issue Nov 4, 2018
as.Date.POSIXct() does not respect the tzone attribute of the POSIXct
object, so the Date is a UTC date. Convert to POSIXlt first, because
as.Date.POSIXlt() does use the timezone and therefore returns a local
date.

See #53, see #277.
joshuaulrich added a commit that referenced this issue May 12, 2019
Conflicts in R/toperiod.R related to:
 - #53 time-based to Date-based index causes duplicate index values)
 - #277 to.daily producing duplicates

Conflicts in R/xts.methods.R related to:
 - #193 time-of-day subset performance

Fixes #245.
@joshuaulrich joshuaulrich added this to the 0.11-2 milestone Jul 4, 2019
@joshuaulrich joshuaulrich self-assigned this Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant