-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Comparing xts objects with 'Date' indices gives warnings #258
Labels
Comments
Your warning (not an error) is because all Date indices have timezone 'UTC', as has been true and documented for a while. Your local timezone is different. Also, you've created a false comparison. xts objects are always ordered by time. You can't create an xts object with a decreasing index. |
Hi Brian,
Thanks for the quick reply. There was a typo in my initial comment. I've
corrected it. The second xts object should have been created with the same
ascending index as the first one. Here's the corrected code example.
library(xts)
a <- xts(1:5, order.by = Sys.Date()+1:5)
b <- xts(5:1,order.by = Sys.Date()+1:5)
res <- a < b
print(res)
print(zoo::index(a))
print(zoo::index(res))
Yes, my local time zone is different than UTC. But I still don't see why
the warnings should have been thrown. I'm merely creating legit xts object
with Sys.Date() and performing innocuous comparison operations. Somehow,
the resultant xts' index is printed with explicit UTC time zone whereas the
input xts' index is not.
print(zoo::index(a))
[1] "2018-07-26" "2018-07-27" "2018-07-28" "2018-07-29" "2018-07-30"
print(zoo::index(res))
[1] "2018-07-26 UTC" "2018-07-27 UTC" "2018-07-28 UTC" "2018-07-29 UTC"
"2018-07-30 UTC"
Brian G. Peterson <notifications@github.com> 于2018年7月24日周二 下午7:48写道:
… Your warning (not an error) is because all Date indices have timezone
'UTC', as has been true and documented for a while. Your local timezone is
different.
Also, you've created a false comparison.
xts objects are always ordered by time. You can't create an xts object
with a decreasing index.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#258 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFMExDykceUa-WXSdyN_BoFedSHw76v0ks5uJwmagaJpZM4VcINX>
.
|
This is a duplicate of #249. Tom Andrews' comment illustrates why this happens: library(xts)
test <- .xts(1:5, 1:5, tclass = "Date")
attr(test > 2, "tclass")
# [1] "POSIXct" "POSIXt" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Comparing xts objects with 'Date' indices gives warnings. The resultant xts object's index seems to be changed to 'POSIXct'.
Expected behavior
Warning message:
timezone of object (UTC) is different than current timezone ().
Minimal, reproducible example
Session Info
The text was updated successfully, but these errors were encountered: