problems in vectors of dates_times

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

problems in vectors of dates_times

tring
Dear friends - I have further problems  handling dates_times, as
demonstrated below where concatenating two formatted vectors of
date_times results in errors.
I wonder why this happens and what was wrong in trying to take these two
vectors together
All best wishes
Troels Ring
Aalborg, Denmark
Windows
R version 3.3.2 (2016-10-31)


A <- structure(c(1364450400, 1364450400, 1364536800, 1364623200,
1364709600,
1364796000, 1364882400, 1364968800, 1365055200, 1365141600, 1365228000,
1365314400, 1365400800), class = c("POSIXct", "POSIXt"), tzone = "UTC")
A
B <- structure(c(1365141600, 1365228000, 1365314400, 1365400800,
1365487200,
1365573600, 1365660000, 1365746400, 1365832800, 1365919200, 1366005600,
1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
B
C <- c(A,B)
C

______________________________________________
[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: problems in vectors of dates_times

Ulrik Stervbo-2
Hi Troels,

I get no error. I think we need more information to be of any help.

Best wishes,
Ulrik

On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]> wrote:

> Dear friends - I have further problems  handling dates_times, as
> demonstrated below where concatenating two formatted vectors of
> date_times results in errors.
> I wonder why this happens and what was wrong in trying to take these two
> vectors together
> All best wishes
> Troels Ring
> Aalborg, Denmark
> Windows
> R version 3.3.2 (2016-10-31)
>
>
> A <- structure(c(1364450400, 1364450400, 1364536800, 1364623200,
> 1364709600,
> 1364796000, 1364882400, 1364968800, 1365055200, 1365141600, 1365228000,
> 1365314400, 1365400800), class = c("POSIXct", "POSIXt"), tzone = "UTC")
> A
> B <- structure(c(1365141600, 1365228000, 1365314400, 1365400800,
> 1365487200,
> 1365573600, 1365660000, 1365746400, 1365832800, 1365919200, 1366005600,
> 1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
> B
> C <- c(A,B)
> C
>
> ______________________________________________
> [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: problems in vectors of dates_times

tring
In reply to this post by tring
Thanks a  lot - perhaps it is just understanding how times dates are
handled, sorry to bother if that is just the case

C[1]==A[1]  # TRUE

but

C[1]
[1] "2013-03-28 07:00:00 CET"
A[1]
[1] "2013-03-28 06:00:00 UTC"





Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:

> Hi Troels,
>
> I get no error. I think we need more information to be of any help.
>
> Best wishes,
> Ulrik
>
> On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]> wrote:
>
>> Dear friends - I have further problems  handling dates_times, as
>> demonstrated below where concatenating two formatted vectors of
>> date_times results in errors.
>> I wonder why this happens and what was wrong in trying to take these two
>> vectors together
>> All best wishes
>> Troels Ring
>> Aalborg, Denmark
>> Windows
>> R version 3.3.2 (2016-10-31)
>>
>>
>> A <- structure(c(1364450400, 1364450400, 1364536800, 1364623200,
>> 1364709600,
>> 1364796000, 1364882400, 1364968800, 1365055200, 1365141600, 1365228000,
>> 1365314400, 1365400800), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>> A
>> B <- structure(c(1365141600, 1365228000, 1365314400, 1365400800,
>> 1365487200,
>> 1365573600, 1365660000, 1365746400, 1365832800, 1365919200, 1366005600,
>> 1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>> B
>> C <- c(A,B)
>> C
>>
>> ______________________________________________
>> [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.
>

______________________________________________
[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: problems in vectors of dates_times

tring
Thanks a lot - good idea:

I put

Sys.setenv(TZ = "UTC")

ahead of the code - solves the problem!

Thanks a lot


Den 07-04-2017 kl. 09:26 skrev Mark Leeds:

> Hi Troels: This is off-list so as to not clog the list with my noise
> because my suggestion may not work. I really don't know that much
> about time-zones. but.   I ran your code and it "worked" but all the
> times were correctly time stamped but they changed from UTC to GMT.
> in time-zone. In your
> case, they changed to something and the time got shifted it looks
> like. So, definitely it has to do with how your time-zones are set. In
> my .Rprofile, I have something.
> Let me check. ... time passes .....  I have below in my .Rprofile. So
> my guess is that, if you want things to remain UTC, then put below
> in your .Rprofile but change it from "GMT" to "UTC". Others may have
> different solutions but that might work. If you don't have that, then
> R decides what to use and I'm not sure how it decides.
>
> Sys.setenv(TZ = "GMT")
>
> #print("LOADING MASS LIBRARY")
> #ibrary("MASS")
> #print("LOADING LATTICE LIBRARY")
> #library("lattice")
>
>
>
>
> :~>
>
> On Fri, Apr 7, 2017 at 3:00 AM, Troels Ring <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Thanks a lot - perhaps it is just understanding how times dates
>     are handled, sorry to bother if that is just the case
>
>     C[1]==A[1]  # TRUE
>
>     but
>
>     C[1]
>     [1] "2013-03-28 07:00:00 CET"
>     A[1]
>     [1] "2013-03-28 06:00:00 UTC"
>
>
>
>
>
>
>     Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:
>
>         Hi Troels,
>
>         I get no error. I think we need more information to be of any
>         help.
>
>         Best wishes,
>         Ulrik
>
>         On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]
>         <mailto:[hidden email]>> wrote:
>
>             Dear friends - I have further problems  handling
>             dates_times, as
>             demonstrated below where concatenating two formatted
>             vectors of
>             date_times results in errors.
>             I wonder why this happens and what was wrong in trying to
>             take these two
>             vectors together
>             All best wishes
>             Troels Ring
>             Aalborg, Denmark
>             Windows
>             R version 3.3.2 (2016-10-31)
>
>
>             A <- structure(c(1364450400, 1364450400, 1364536800,
>             1364623200,
>             1364709600,
>             1364796000, 1364882400, 1364968800, 1365055200,
>             1365141600, 1365228000,
>             1365314400, 1365400800), class = c("POSIXct", "POSIXt"),
>             tzone = "UTC")
>             A
>             B <- structure(c(1365141600, 1365228000, 1365314400,
>             1365400800,
>             1365487200,
>             1365573600, 1365660000, 1365746400, 1365832800,
>             1365919200, 1366005600,
>             1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>             B
>             C <- c(A,B)
>             C
>
>             ______________________________________________
>             [hidden email] <mailto:[hidden email]> mailing
>             list -- To UNSUBSCRIBE and more, see
>             https://stat.ethz.ch/mailman/listinfo/r-help
>             <https://stat.ethz.ch/mailman/listinfo/r-help>
>             PLEASE do read the posting guide
>             http://www.R-project.org/posting-guide.html
>             <http://www.R-project.org/posting-guide.html>
>             and provide commented, minimal, self-contained,
>             reproducible code.
>
>                 [[alternative HTML version deleted]]
>
>         ______________________________________________
>         [hidden email] <mailto:[hidden email]> mailing
>         list -- To UNSUBSCRIBE and more, see
>         https://stat.ethz.ch/mailman/listinfo/r-help
>         <https://stat.ethz.ch/mailman/listinfo/r-help>
>         PLEASE do read the posting guide
>         http://www.R-project.org/posting-guide.html
>         <http://www.R-project.org/posting-guide.html>
>         and provide commented, minimal, self-contained, reproducible code.
>
>
>     ______________________________________________
>     [hidden email] <mailto:[hidden email]> mailing list --
>     To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     <https://stat.ethz.ch/mailman/listinfo/r-help>
>     PLEASE do read the posting guide
>     http://www.R-project.org/posting-guide.html
>     <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: problems in vectors of dates_times

Jeff Newmiller
In reply to this post by tring
R does a poor job of supporting timezone-specific objects... you have to transfer the necessary attributes explicitly for many operations.  (It does no job of supporting element-specific timezones so don't go there.)

The good news is that R is pretty good at working with points in time, since the default behavior of implementing time with numeric values in GMT always means you can specify whatever timezone you want input or output to use, and the timestamps are always ordered correctly in time.

I find that using the default empty string for tz attributes on POSIXt objects (meaning use whatever is default) and letting the TZ environment variable control the "current default" timezone is the most effective way to avoid frustration with this. Don't hesitate to change that variable when you need to convert to or from character or POSIXlt..

Sys.setenv( TZ="Etc/GMT+5" ) # read ?Olson
x <- as.POSIXct( "2017-03-31 19:00:00" )
Sys.setenv( TZ="Etc/GMT+8" )
y <- as.POSIXct( "2017-03-31 16:00:00" )
Sys.setenv( TZ="GMT" )
print( x )
print( y )
--
Sent from my phone. Please excuse my brevity.

On April 7, 2017 12:00:52 AM PDT, Troels Ring <[hidden email]> wrote:

>Thanks a  lot - perhaps it is just understanding how times dates are
>handled, sorry to bother if that is just the case
>
>C[1]==A[1]  # TRUE
>
>but
>
>C[1]
>[1] "2013-03-28 07:00:00 CET"
>A[1]
>[1] "2013-03-28 06:00:00 UTC"
>
>
>
>
>
>Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:
>> Hi Troels,
>>
>> I get no error. I think we need more information to be of any help.
>>
>> Best wishes,
>> Ulrik
>>
>> On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]> wrote:
>>
>>> Dear friends - I have further problems  handling dates_times, as
>>> demonstrated below where concatenating two formatted vectors of
>>> date_times results in errors.
>>> I wonder why this happens and what was wrong in trying to take these
>two
>>> vectors together
>>> All best wishes
>>> Troels Ring
>>> Aalborg, Denmark
>>> Windows
>>> R version 3.3.2 (2016-10-31)
>>>
>>>
>>> A <- structure(c(1364450400, 1364450400, 1364536800, 1364623200,
>>> 1364709600,
>>> 1364796000, 1364882400, 1364968800, 1365055200, 1365141600,
>1365228000,
>>> 1365314400, 1365400800), class = c("POSIXct", "POSIXt"), tzone =
>"UTC")
>>> A
>>> B <- structure(c(1365141600, 1365228000, 1365314400, 1365400800,
>>> 1365487200,
>>> 1365573600, 1365660000, 1365746400, 1365832800, 1365919200,
>1366005600,
>>> 1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>>> B
>>> C <- c(A,B)
>>> C
>>>
>>> ______________________________________________
>>> [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.
>>
>
>______________________________________________
>[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: problems in vectors of dates_times

R help mailing list-2
I believe the lubridate package does a good job with time zones.

> install.packages("lubridate")
> library(lubridate)


Look at the supplied functions  with_tz()  and  force_tz().

HTH,

Bill.

William J. Michels, Ph.D.



On Fri, Apr 7, 2017 at 12:52 AM, Jeff Newmiller
<[hidden email]> wrote:

> R does a poor job of supporting timezone-specific objects... you have to transfer the necessary attributes explicitly for many operations.  (It does no job of supporting element-specific timezones so don't go there.)
>
> The good news is that R is pretty good at working with points in time, since the default behavior of implementing time with numeric values in GMT always means you can specify whatever timezone you want input or output to use, and the timestamps are always ordered correctly in time.
>
> I find that using the default empty string for tz attributes on POSIXt objects (meaning use whatever is default) and letting the TZ environment variable control the "current default" timezone is the most effective way to avoid frustration with this. Don't hesitate to change that variable when you need to convert to or from character or POSIXlt..
>
> Sys.setenv( TZ="Etc/GMT+5" ) # read ?Olson
> x <- as.POSIXct( "2017-03-31 19:00:00" )
> Sys.setenv( TZ="Etc/GMT+8" )
> y <- as.POSIXct( "2017-03-31 16:00:00" )
> Sys.setenv( TZ="GMT" )
> print( x )
> print( y )
> --
> Sent from my phone. Please excuse my brevity.
>
> On April 7, 2017 12:00:52 AM PDT, Troels Ring <[hidden email]> wrote:
>>Thanks a  lot - perhaps it is just understanding how times dates are
>>handled, sorry to bother if that is just the case
>>
>>C[1]==A[1]  # TRUE
>>
>>but
>>
>>C[1]
>>[1] "2013-03-28 07:00:00 CET"
>>A[1]
>>[1] "2013-03-28 06:00:00 UTC"
>>
>>
>>
>>
>>
>>Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:
>>> Hi Troels,
>>>
>>> I get no error. I think we need more information to be of any help.
>>>
>>> Best wishes,
>>> Ulrik
>>>
>>> On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]> wrote:
>>>
>>>> Dear friends - I have further problems  handling dates_times, as
>>>> demonstrated below where concatenating two formatted vectors of
>>>> date_times results in errors.
>>>> I wonder why this happens and what was wrong in trying to take these
>>two
>>>> vectors together
>>>> All best wishes
>>>> Troels Ring
>>>> Aalborg, Denmark
>>>> Windows
>>>> R version 3.3.2 (2016-10-31)
>>>>
>>>>
>>>> A <- structure(c(1364450400, 1364450400, 1364536800, 1364623200,
>>>> 1364709600,
>>>> 1364796000, 1364882400, 1364968800, 1365055200, 1365141600,
>>1365228000,
>>>> 1365314400, 1365400800), class = c("POSIXct", "POSIXt"), tzone =
>>"UTC")
>>>> A
>>>> B <- structure(c(1365141600, 1365228000, 1365314400, 1365400800,
>>>> 1365487200,
>>>> 1365573600, 1365660000, 1365746400, 1365832800, 1365919200,
>>1366005600,
>>>> 1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>>>> B
>>>> C <- c(A,B)
>>>> C
>>>>
>>>> ______________________________________________
>>>> [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.
>>>
>>
>>______________________________________________
>>[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: problems in vectors of dates_times

MacQueen, Don
In reply to this post by tring
I think a more illuminating inspection is this:

> attributes(A)
$class
[1] "POSIXct" "POSIXt"

$tzone
[1] "UTC"

> attributes(B)
$class
[1] "POSIXct" "POSIXt"

$tzone
[1] "UTC"

> attributes(C)
$class
[1] "POSIXct" "POSIXt"

Note that the operation c(A,B) loses the $tzone attribute.

Note also that C[1] and A[1] are actually the same point in time -- my default time zone, PDT, is 7 hours behind UTC -- but they display differently, due to the different tzone attribute.
> C[1]
[1] "2013-03-27 23:00:00 PDT"
> A[1]
[1] "2013-03-28 06:00:00 UTC"

> A[1]==C[1]
[1] TRUE

Finally, if I do this:
attributes(C)$tzone <- attributes(A)$tzone

Then they display the same:
> C[1]
[1] "2013-03-28 06:00:00 UTC"
> A[1]
[1] "2013-03-28 06:00:00 UTC"

It's a tossup whether resetting the lost attribute is preferable to setting the system timezone.

Then there's the design question of whether the c() operation should lose the tzone attribute. In this case it would be nice if it didn't, but what should happen if we use c() on two objects with  different tzone attributed??

--
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062


On 4/7/17, 12:48 AM, "R-help on behalf of Troels Ring" <[hidden email] on behalf of [hidden email]> wrote:

    Thanks a lot - good idea:
   
    I put
   
    Sys.setenv(TZ = "UTC")
   
    ahead of the code - solves the problem!
   
    Thanks a lot
   
   
    Den 07-04-2017 kl. 09:26 skrev Mark Leeds:
    > Hi Troels: This is off-list so as to not clog the list with my noise
    > because my suggestion may not work. I really don't know that much
    > about time-zones. but.   I ran your code and it "worked" but all the
    > times were correctly time stamped but they changed from UTC to GMT.
    > in time-zone. In your
    > case, they changed to something and the time got shifted it looks
    > like. So, definitely it has to do with how your time-zones are set. In
    > my .Rprofile, I have something.
    > Let me check. ... time passes .....  I have below in my .Rprofile. So
    > my guess is that, if you want things to remain UTC, then put below
    > in your .Rprofile but change it from "GMT" to "UTC". Others may have
    > different solutions but that might work. If you don't have that, then
    > R decides what to use and I'm not sure how it decides.
    >
    > Sys.setenv(TZ = "GMT")
    >
    > #print("LOADING MASS LIBRARY")
    > #ibrary("MASS")
    > #print("LOADING LATTICE LIBRARY")
    > #library("lattice")
    >
    >
    >
    >
    > :~>
    >
    > On Fri, Apr 7, 2017 at 3:00 AM, Troels Ring <[hidden email]
    > <mailto:[hidden email]>> wrote:
    >
    >     Thanks a lot - perhaps it is just understanding how times dates
    >     are handled, sorry to bother if that is just the case
    >
    >     C[1]==A[1]  # TRUE
    >
    >     but
    >
    >     C[1]
    >     [1] "2013-03-28 07:00:00 CET"
    >     A[1]
    >     [1] "2013-03-28 06:00:00 UTC"
    >
    >
    >
    >
    >
    >
    >     Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:
    >
    >         Hi Troels,
    >
    >         I get no error. I think we need more information to be of any
    >         help.
    >
    >         Best wishes,
    >         Ulrik
    >
    >         On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]
    >         <mailto:[hidden email]>> wrote:
    >
    >             Dear friends - I have further problems  handling
    >             dates_times, as
    >             demonstrated below where concatenating two formatted
    >             vectors of
    >             date_times results in errors.
    >             I wonder why this happens and what was wrong in trying to
    >             take these two
    >             vectors together
    >             All best wishes
    >             Troels Ring
    >             Aalborg, Denmark
    >             Windows
    >             R version 3.3.2 (2016-10-31)
    >
    >
    >             A <- structure(c(1364450400, 1364450400, 1364536800,
    >             1364623200,
    >             1364709600,
    >             1364796000, 1364882400, 1364968800, 1365055200,
    >             1365141600, 1365228000,
    >             1365314400, 1365400800), class = c("POSIXct", "POSIXt"),
    >             tzone = "UTC")
    >             A
    >             B <- structure(c(1365141600, 1365228000, 1365314400,
    >             1365400800,
    >             1365487200,
    >             1365573600, 1365660000, 1365746400, 1365832800,
    >             1365919200, 1366005600,
    >             1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
    >             B
    >             C <- c(A,B)
    >             C
    >
    >             ______________________________________________
    >             [hidden email] <mailto:[hidden email]> mailing
    >             list -- To UNSUBSCRIBE and more, see
    >             https://stat.ethz.ch/mailman/listinfo/r-help
    >             <https://stat.ethz.ch/mailman/listinfo/r-help>
    >             PLEASE do read the posting guide
    >             http://www.R-project.org/posting-guide.html
    >             <http://www.R-project.org/posting-guide.html>
    >             and provide commented, minimal, self-contained,
    >             reproducible code.
    >
    >                 [[alternative HTML version deleted]]
    >
    >         ______________________________________________
    >         [hidden email] <mailto:[hidden email]> mailing
    >         list -- To UNSUBSCRIBE and more, see
    >         https://stat.ethz.ch/mailman/listinfo/r-help
    >         <https://stat.ethz.ch/mailman/listinfo/r-help>
    >         PLEASE do read the posting guide
    >         http://www.R-project.org/posting-guide.html
    >         <http://www.R-project.org/posting-guide.html>
    >         and provide commented, minimal, self-contained, reproducible code.
    >
    >
    >     ______________________________________________
    >     [hidden email] <mailto:[hidden email]> mailing list --
    >     To UNSUBSCRIBE and more, see
    >     https://stat.ethz.ch/mailman/listinfo/r-help
    >     <https://stat.ethz.ch/mailman/listinfo/r-help>
    >     PLEASE do read the posting guide
    >     http://www.R-project.org/posting-guide.html
    >     <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.
   

______________________________________________
[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: problems in vectors of dates_times

Richard M. Heiberger
Don asks a good question.  Here is the analogy from the grid package.

> library(grid)
> unit(12, "in")
[1] 12in
> unit(12, "cm")
[1] 12cm
> unit.c(unit(12, "in"), unit(12, "cm"))
[1] 12in 12cm
> c(unit(12, "in"), unit(12, "cm"))
[1] 12 12
> ?unit
> convertUnit(c(unit(12, "in"), unit(12, "cm")), "in")
Error in convertUnit(c(unit(12, "in"), unit(12, "cm")), "in") :
  'x' argument must be a unit object
> convertUnit(unit.c(unit(12, "in"), unit(12, "cm")), "in")
[1] 12in              4.7244094488189in
>

On Fri, Apr 7, 2017 at 6:33 PM, MacQueen, Don <[hidden email]> wrote:

> I think a more illuminating inspection is this:
>
>> attributes(A)
> $class
> [1] "POSIXct" "POSIXt"
>
> $tzone
> [1] "UTC"
>
>> attributes(B)
> $class
> [1] "POSIXct" "POSIXt"
>
> $tzone
> [1] "UTC"
>
>> attributes(C)
> $class
> [1] "POSIXct" "POSIXt"
>
> Note that the operation c(A,B) loses the $tzone attribute.
>
> Note also that C[1] and A[1] are actually the same point in time -- my default time zone, PDT, is 7 hours behind UTC -- but they display differently, due to the different tzone attribute.
>> C[1]
> [1] "2013-03-27 23:00:00 PDT"
>> A[1]
> [1] "2013-03-28 06:00:00 UTC"
>
>> A[1]==C[1]
> [1] TRUE
>
> Finally, if I do this:
> attributes(C)$tzone <- attributes(A)$tzone
>
> Then they display the same:
>> C[1]
> [1] "2013-03-28 06:00:00 UTC"
>> A[1]
> [1] "2013-03-28 06:00:00 UTC"
>
> It's a tossup whether resetting the lost attribute is preferable to setting the system timezone.
>
> Then there's the design question of whether the c() operation should lose the tzone attribute. In this case it would be nice if it didn't, but what should happen if we use c() on two objects with  different tzone attributed??
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
>
> On 4/7/17, 12:48 AM, "R-help on behalf of Troels Ring" <[hidden email] on behalf of [hidden email]> wrote:
>
>     Thanks a lot - good idea:
>
>     I put
>
>     Sys.setenv(TZ = "UTC")
>
>     ahead of the code - solves the problem!
>
>     Thanks a lot
>
>
>     Den 07-04-2017 kl. 09:26 skrev Mark Leeds:
>     > Hi Troels: This is off-list so as to not clog the list with my noise
>     > because my suggestion may not work. I really don't know that much
>     > about time-zones. but.   I ran your code and it "worked" but all the
>     > times were correctly time stamped but they changed from UTC to GMT.
>     > in time-zone. In your
>     > case, they changed to something and the time got shifted it looks
>     > like. So, definitely it has to do with how your time-zones are set. In
>     > my .Rprofile, I have something.
>     > Let me check. ... time passes .....  I have below in my .Rprofile. So
>     > my guess is that, if you want things to remain UTC, then put below
>     > in your .Rprofile but change it from "GMT" to "UTC". Others may have
>     > different solutions but that might work. If you don't have that, then
>     > R decides what to use and I'm not sure how it decides.
>     >
>     > Sys.setenv(TZ = "GMT")
>     >
>     > #print("LOADING MASS LIBRARY")
>     > #ibrary("MASS")
>     > #print("LOADING LATTICE LIBRARY")
>     > #library("lattice")
>     >
>     >
>     >
>     >
>     > :~>
>     >
>     > On Fri, Apr 7, 2017 at 3:00 AM, Troels Ring <[hidden email]
>     > <mailto:[hidden email]>> wrote:
>     >
>     >     Thanks a lot - perhaps it is just understanding how times dates
>     >     are handled, sorry to bother if that is just the case
>     >
>     >     C[1]==A[1]  # TRUE
>     >
>     >     but
>     >
>     >     C[1]
>     >     [1] "2013-03-28 07:00:00 CET"
>     >     A[1]
>     >     [1] "2013-03-28 06:00:00 UTC"
>     >
>     >
>     >
>     >
>     >
>     >
>     >     Den 07-04-2017 kl. 08:27 skrev Ulrik Stervbo:
>     >
>     >         Hi Troels,
>     >
>     >         I get no error. I think we need more information to be of any
>     >         help.
>     >
>     >         Best wishes,
>     >         Ulrik
>     >
>     >         On Fri, 7 Apr 2017 at 08:17 Troels Ring <[hidden email]
>     >         <mailto:[hidden email]>> wrote:
>     >
>     >             Dear friends - I have further problems  handling
>     >             dates_times, as
>     >             demonstrated below where concatenating two formatted
>     >             vectors of
>     >             date_times results in errors.
>     >             I wonder why this happens and what was wrong in trying to
>     >             take these two
>     >             vectors together
>     >             All best wishes
>     >             Troels Ring
>     >             Aalborg, Denmark
>     >             Windows
>     >             R version 3.3.2 (2016-10-31)
>     >
>     >
>     >             A <- structure(c(1364450400, 1364450400, 1364536800,
>     >             1364623200,
>     >             1364709600,
>     >             1364796000, 1364882400, 1364968800, 1365055200,
>     >             1365141600, 1365228000,
>     >             1365314400, 1365400800), class = c("POSIXct", "POSIXt"),
>     >             tzone = "UTC")
>     >             A
>     >             B <- structure(c(1365141600, 1365228000, 1365314400,
>     >             1365400800,
>     >             1365487200,
>     >             1365573600, 1365660000, 1365746400, 1365832800,
>     >             1365919200, 1366005600,
>     >             1366092000), class = c("POSIXct", "POSIXt"), tzone = "UTC")
>     >             B
>     >             C <- c(A,B)
>     >             C
>     >
>     >             ______________________________________________
>     >             [hidden email] <mailto:[hidden email]> mailing
>     >             list -- To UNSUBSCRIBE and more, see
>     >             https://stat.ethz.ch/mailman/listinfo/r-help
>     >             <https://stat.ethz.ch/mailman/listinfo/r-help>
>     >             PLEASE do read the posting guide
>     >             http://www.R-project.org/posting-guide.html
>     >             <http://www.R-project.org/posting-guide.html>
>     >             and provide commented, minimal, self-contained,
>     >             reproducible code.
>     >
>     >                 [[alternative HTML version deleted]]
>     >
>     >         ______________________________________________
>     >         [hidden email] <mailto:[hidden email]> mailing
>     >         list -- To UNSUBSCRIBE and more, see
>     >         https://stat.ethz.ch/mailman/listinfo/r-help
>     >         <https://stat.ethz.ch/mailman/listinfo/r-help>
>     >         PLEASE do read the posting guide
>     >         http://www.R-project.org/posting-guide.html
>     >         <http://www.R-project.org/posting-guide.html>
>     >         and provide commented, minimal, self-contained, reproducible code.
>     >
>     >
>     >     ______________________________________________
>     >     [hidden email] <mailto:[hidden email]> mailing list --
>     >     To UNSUBSCRIBE and more, see
>     >     https://stat.ethz.ch/mailman/listinfo/r-help
>     >     <https://stat.ethz.ch/mailman/listinfo/r-help>
>     >     PLEASE do read the posting guide
>     >     http://www.R-project.org/posting-guide.html
>     >     <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.
>
>
> ______________________________________________
> [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.