Zoo changing time-zone when I merge 2 zoo time series

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Zoo changing time-zone when I merge 2 zoo time series

Bogaso
Hi,

Below is my code :

library(zoo)
Dat1 = structure(c(17890, 17770.01, 17600, 17593, 17630.01), index =
structure(c(1512664740,
1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
"POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
Dat2 = structure(c(15804.28, 15720.61, 15770, 15750, 15770), index =
structure(c(1512664740,
1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
"POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")

merge(Dat1, Dat2)

                        Dat1     Dat2
2017-12-07 22:09:00 17890.00 15804.28
2017-12-07 22:10:00 17770.01 15720.61
2017-12-07 22:11:00 17600.00 15770.00
2017-12-07 22:12:00 17593.00 15750.00
2017-12-07 22:13:00 17630.01 15770.00


So, after merging the TZ of the original series got changed.

Appreciate if someone points what went wrong

        [[alternative HTML version deleted]]

______________________________________________
[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: Zoo changing time-zone when I merge 2 zoo time series

Eric Berger
I found the following at
https://stackoverflow.com/questions/25269425/merge-zoo-removes-time-zone

library(xts)

merge2=function(x,y) {
  as.zoo(merge(as.xts(x), as.xts(y)))}

If you define the function merge2() as above then

merge2(Dat1,Dat2)

should be ok

HTH,
Eric


On Mon, Jul 9, 2018 at 1:22 PM, Christofer Bogaso <
[hidden email]> wrote:

> Hi,
>
> Below is my code :
>
> library(zoo)
> Dat1 = structure(c(17890, 17770.01, 17600, 17593, 17630.01), index =
> structure(c(1512664740,
> 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
> Dat2 = structure(c(15804.28, 15720.61, 15770, 15750, 15770), index =
> structure(c(1512664740,
> 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
>
> merge(Dat1, Dat2)
>
>                         Dat1     Dat2
> 2017-12-07 22:09:00 17890.00 15804.28
> 2017-12-07 22:10:00 17770.01 15720.61
> 2017-12-07 22:11:00 17600.00 15770.00
> 2017-12-07 22:12:00 17593.00 15750.00
> 2017-12-07 22:13:00 17630.01 15770.00
>
>
> So, after merging the TZ of the original series got changed.
>
> Appreciate if someone points what went wrong
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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: Zoo changing time-zone when I merge 2 zoo time series

Bogaso
In reply to this post by Bogaso
My default is set as GMT.

On Mon, Jul 9, 2018 at 4:01 PM David Wolfskill <[hidden email]> wrote:

> On Mon, Jul 09, 2018 at 03:52:02PM +0530, Christofer Bogaso wrote:
> > Hi,
> >
> > Below is my code :
> >
> > library(zoo)
> > Dat1 = structure(c(17890, 17770.01, 17600, 17593, 17630.01), index =
> > structure(c(1512664740,
> > 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> > "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
> > Dat2 = structure(c(15804.28, 15720.61, 15770, 15750, 15770), index =
> > structure(c(1512664740,
> > 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> > "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
> >
> > merge(Dat1, Dat2)
> >
> >                         Dat1     Dat2
> > 2017-12-07 22:09:00 17890.00 15804.28
> > 2017-12-07 22:10:00 17770.01 15720.61
> > 2017-12-07 22:11:00 17600.00 15770.00
> > 2017-12-07 22:12:00 17593.00 15750.00
> > 2017-12-07 22:13:00 17630.01 15770.00
> >
> >
> > So, after merging the TZ of the original series got changed.
> >
> > Appreciate if someone points what went wrong
> > ....
>
> Well... when I do the above, I see:
>
> > Dat1
> 2017-12-07 08:39:00 2017-12-07 08:40:00 2017-12-07 08:41:00 2017-12-07
> 08:42:00
>            17890.00            17770.01            17600.00
> 17593.00
> 2017-12-07 08:43:00
>            17630.01
> > Dat2
> 2017-12-07 08:39:00 2017-12-07 08:40:00 2017-12-07 08:41:00 2017-12-07
> 08:42:00
>            15804.28            15720.61            15770.00
> 15750.00
> 2017-12-07 08:43:00
>            15770.00
> > merge(Dat1, Dat2)
>
>                         Dat1     Dat2
> 2017-12-07 08:39:00 17890.00 15804.28
> 2017-12-07 08:40:00 17770.01 15720.61
> 2017-12-07 08:41:00 17600.00 15770.00
> 2017-12-07 08:42:00 17593.00 15750.00
> 2017-12-07 08:43:00 17630.01 15770.00
> >
>
> That said, one aspect that may be relevant:
> > Sys.timezone()
> [1] "America/Los_Angeles"
>
> What's yours?
>
>
> Peace,
> david
> --
> David H. Wolfskill                              [hidden email]
> "Fly, Trump Baby!" -- only the biggest, YUGEST insults for Donald J. Trump!
>
> See http://www.catwhisker.org/~david/publickey.gpg for my public key.
>

        [[alternative HTML version deleted]]

______________________________________________
[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: Zoo changing time-zone when I merge 2 zoo time series

Enrico Schumann-2
In reply to this post by Bogaso
On Mon, 09 Jul 2018, Christofer Bogaso writes:

> Hi,
>
> Below is my code :
>
> library(zoo)
> Dat1 = structure(c(17890, 17770.01, 17600, 17593, 17630.01), index =
> structure(c(1512664740,
> 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
> Dat2 = structure(c(15804.28, 15720.61, 15770, 15750, 15770), index =
> structure(c(1512664740,
> 1512664800, 1512664860, 1512664920, 1512664980), class = c("POSIXct",
> "POSIXt"), tzone = "America/Los_Angeles"), class = "zoo")
>
> merge(Dat1, Dat2)
>
>                         Dat1     Dat2
> 2017-12-07 22:09:00 17890.00 15804.28
> 2017-12-07 22:10:00 17770.01 15720.61
> 2017-12-07 22:11:00 17600.00 15770.00
> 2017-12-07 22:12:00 17593.00 15750.00
> 2017-12-07 22:13:00 17630.01 15770.00
>
>
> So, after merging the TZ of the original series got changed.
>
> Appreciate if someone points what went wrong
>

Nothing went wrong. Only 'merge.zoo' drops the
time-zone attribute.  But note that it did not change
the actual times:

  unclass(index(Dat1))
  ## [1] 1512664740 1512664800 1512664860 1512664920 1512664980
  ## attr(,"tzone")
  ## [1] "America/Los_Angeles"

  unclass(index(merge(Dat1, Dat2)))
  ## [1] 1512664740 1512664800 1512664860 1512664920 1512664980

  all(unclass(index(Dat1)) == unclass(index(merge(Dat1, Dat2))))
  ## [1] TRUE

  M <- merge(Dat1, Dat2)
  attr(index(M), "tzone") <- attr(index(Dat1), "tzone")
  M
  ##                         Dat1     Dat2
  ## 2017-12-07 08:39:00 17890.00 15804.28
  ## 2017-12-07 08:40:00 17770.01 15720.61
  ## 2017-12-07 08:41:00 17600.00 15770.00
  ## 2017-12-07 08:42:00 17593.00 15750.00
  ## 2017-12-07 08:43:00 17630.01 15770.00


See Ripley, B. D. and Hornik, K. (2001) Date-time
classes. R News, 1/2,
8–11. https://www.r-project.org/doc/Rnews/Rnews_2001-2.pdf



--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net

______________________________________________
[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.