xts/zoo index problem?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

xts/zoo index problem?

zadig
Dear all,

I have this code :

library(xts)
a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
"POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
1L), .Dimnames = list(NULL, "value"))

a

a["2016-01-18 12:24:45.230"]
#                    value
#2016-01-18 12:24:45     1

a["2016-01-18 15:31:54.078"]
#                   value

Why second line doesn't show the value? Something to do with miliseconds ?
Thanks
CE

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

zadig

yes it shows , more interesting :

>  a["2016-01-18 15:31:54.0"]
                    value
2016-01-18 15:31:54     2

> a["2016-01-18 15:31:54.07"]
     value

> a["2016-01-18 15:31:54.079"]
                    value
2016-01-18 15:31:54     2


why it doesn't work with .07 milisecond  but work with .079  and .0 ??


-----Original Message-----
From: "Huzefa Khalil" [[hidden email]]
Date: 01/18/2016 09:26 PM
To: "ce" <[hidden email]>
CC: [hidden email]
Subject: Re: [R] xts/zoo index problem?

Try

a["2016-01-18 15:31:54.079"]

The question though is why R displays the milliseconds as "078", when
it is clearly "079"...

-h



On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:

> Dear all,
>
> I have this code :
>
> library(xts)
> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
> 1L), .Dimnames = list(NULL, "value"))
>
> a
>
> a["2016-01-18 12:24:45.230"]
> #                    value
> #2016-01-18 12:24:45     1
>
> a["2016-01-18 15:31:54.078"]
> #                   value
>
> Why second line doesn't show the value? Something to do with miliseconds ?
> Thanks
> CE
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

Huzefa Khalil
In reply to this post by zadig
Try

a["2016-01-18 15:31:54.079"]

The question though is why R displays the milliseconds as "078", when
it is clearly "079"...

-h



On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:

> Dear all,
>
> I have this code :
>
> library(xts)
> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
> 1L), .Dimnames = list(NULL, "value"))
>
> a
>
> a["2016-01-18 12:24:45.230"]
> #                    value
> #2016-01-18 12:24:45     1
>
> a["2016-01-18 15:31:54.078"]
> #                   value
>
> Why second line doesn't show the value? Something to do with miliseconds ?
> Thanks
> CE
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

Huzefa Khalil
In reply to this post by zadig
Well it works when you don't put the milliseconds because it is
matching that part of the date which is provided. Hence, the following
all work:

a["2016-01-18 15:31:54.0"]
a["2016-01-18 15:31:54"]
a["2016-01-18 15:31"]
a["2016-01-18 15"]

However, what I don't get is why it is showing 1453149114.079 as
"2016-01-18 15:31:54.078". It should be showing it as "2016-01-18
15:31:54.079".

Anybody?

On Mon, Jan 18, 2016 at 9:31 PM, ce <[hidden email]> wrote:

>
> yes it shows , more interesting :
>
>>  a["2016-01-18 15:31:54.0"]
>                     value
> 2016-01-18 15:31:54     2
>
>> a["2016-01-18 15:31:54.07"]
>      value
>
>> a["2016-01-18 15:31:54.079"]
>                     value
> 2016-01-18 15:31:54     2
>
>
> why it doesn't work with .07 milisecond  but work with .079  and .0 ??
>
>
> -----Original Message-----
> From: "Huzefa Khalil" [[hidden email]]
> Date: 01/18/2016 09:26 PM
> To: "ce" <[hidden email]>
> CC: [hidden email]
> Subject: Re: [R] xts/zoo index problem?
>
> Try
>
> a["2016-01-18 15:31:54.079"]
>
> The question though is why R displays the milliseconds as "078", when
> it is clearly "079"...
>
> -h
>
>
>
> On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:
>> Dear all,
>>
>> I have this code :
>>
>> library(xts)
>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>> 1L), .Dimnames = list(NULL, "value"))
>>
>> a
>>
>> a["2016-01-18 12:24:45.230"]
>> #                    value
>> #2016-01-18 12:24:45     1
>>
>> a["2016-01-18 15:31:54.078"]
>> #                   value
>>
>> Why second line doesn't show the value? Something to do with miliseconds ?
>> Thanks
>> CE
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

Joshua Ulrich
In reply to this post by zadig
On Mon, Jan 18, 2016 at 8:31 PM, ce <[hidden email]> wrote:

>
> yes it shows , more interesting :
>
>>  a["2016-01-18 15:31:54.0"]
>                     value
> 2016-01-18 15:31:54     2
>
>> a["2016-01-18 15:31:54.07"]
>      value
>
>> a["2016-01-18 15:31:54.079"]
>                     value
> 2016-01-18 15:31:54     2
>
>
> why it doesn't work with .07 milisecond  but work with .079  and .0 ??
>
It's not surprising why it doesn't work with 0.070.  It doesn't work
because that's not what the milliseconds component is.  It's also not
surprising why it works with 0.079, because that's what the
milliseconds component is (how something prints is not what it is
equal to).  It is a bit surprising that a value is returned when the
milliseconds component is zero.

>
> -----Original Message-----
> From: "Huzefa Khalil" [[hidden email]]
> Date: 01/18/2016 09:26 PM
> To: "ce" <[hidden email]>
> CC: [hidden email]
> Subject: Re: [R] xts/zoo index problem?
>
> Try
>
> a["2016-01-18 15:31:54.079"]
>
> The question though is why R displays the milliseconds as "078", when
> it is clearly "079"...
>
See this StackOverflow question for discussion around why R prints
fractional seconds the way it does:
http://stackoverflow.com/q/7726034/271616

> -h
>
>
>
> On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:
>> Dear all,
>>
>> I have this code :
>>
>> library(xts)
>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>> 1L), .Dimnames = list(NULL, "value"))
>>
Use a specific timezone.  Everyone does not share your local timezone,
and you don't say what it is.

library(xts)
# don't warn about object TZ vs local TZ differences
options(xts_check_TZ=FALSE, digits.secs=6)
a <- structure(1:2,
  class = c("xts", "zoo"), .indexCLASS=c("POSIXct", "POSIXt"),
  .indexTZ = "UTC", tclass = c("POSIXct", "POSIXt"), tzone = "UTC",
  index = structure(c(1453137885.23, 1453149114.079), tzone = "UTC",
  tclass = c("POSIXct", "POSIXt")), .Dim = c(2L, 1L),
  .Dimnames = list(NULL, "value"))

>> a
>>
>> a["2016-01-18 12:24:45.230"]
>> #                    value
>> #2016-01-18 12:24:45     1
>>
>> a["2016-01-18 15:31:54.078"]
>> #                   value
>>
>> Why second line doesn't show the value? Something to do with miliseconds ?
>> Thanks
>> CE
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

Bert Gunter-2
In reply to this post by Huzefa Khalil
FAQ 7.31 maybe. (Unless special software is used) Only a finite number
of numbers can be represented exactly on a computer.

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Jan 18, 2016 at 6:26 PM, Huzefa Khalil <[hidden email]> wrote:

> Try
>
> a["2016-01-18 15:31:54.079"]
>
> The question though is why R displays the milliseconds as "078", when
> it is clearly "079"...
>
> -h
>
>
>
> On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:
>> Dear all,
>>
>> I have this code :
>>
>> library(xts)
>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>> 1L), .Dimnames = list(NULL, "value"))
>>
>> a
>>
>> a["2016-01-18 12:24:45.230"]
>> #                    value
>> #2016-01-18 12:24:45     1
>>
>> a["2016-01-18 15:31:54.078"]
>> #                   value
>>
>> Why second line doesn't show the value? Something to do with miliseconds ?
>> Thanks
>> CE
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: xts/zoo index problem?

David Winsemius

> On Jan 19, 2016, at 7:44 AM, Bert Gunter <[hidden email]> wrote:
>
> FAQ 7.31 maybe. (Unless special software is used) Only a finite number
> of numbers can be represented exactly on a computer.

Agree that seemed the likely explanation out of the gate. Here's the evidence.

> print( as.numeric(index(a), "%OS3"), digits=20)
[1] 1453137885.2300000191 1453149114.0789999962

--
Best;

>
> Cheers,
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Mon, Jan 18, 2016 at 6:26 PM, Huzefa Khalil <[hidden email]> wrote:
>> Try
>>
>> a["2016-01-18 15:31:54.079"]
>>
>> The question though is why R displays the milliseconds as "078", when
>> it is clearly "079"...
>>
>> -h
>>
>>
>>
>> On Mon, Jan 18, 2016 at 8:55 PM, ce <[hidden email]> wrote:
>>> Dear all,
>>>
>>> I have this code :
>>>
>>> library(xts)
>>> a <- structure(c(1,2), class = c("xts", "zoo"), .indexCLASS = c("POSIXct",
>>> "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", index = structure(c(1453137885.23,
>>> 1453149114.079), tzone = "", tclass = c("POSIXct", "POSIXt")), .Dim = c(2L,
>>> 1L), .Dimnames = list(NULL, "value"))
>>>
>>> a
>>>
>>> a["2016-01-18 12:24:45.230"]
>>> #                    value
>>> #2016-01-18 12:24:45     1
>>>
>>> a["2016-01-18 15:31:54.078"]
>>> #                   value
>>>
>>> Why second line doesn't show the value? Something to do with miliseconds ?
>>> Thanks
>>> CE
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.