On Fri, Mar 30, 2012 at 2:53 PM, Joshua Ulrich <josh.m.ulr...@gmail.com>wrote:

> On Thu, Mar 29, 2012 at 3:56 PM, Worik R <wor...@gmail.com> wrote:
>
>

> I removed the (not so minimal) reproducible example because you can
> get the same behavior via:
> > (s <- Sys.time())
> [1] "2012-03-29 20:43:35 CDT"
> > as.POSIXct(as.numeric(s),origin="1970-01-01")
> [1] "2012-03-30 02:43:35 CDT"
>
> sapply() attempts to simplify to an array.  Arrays can only contain an
> atomic type.  POSIXct is not an atomic type, so it gets converted to
> numeric.
>
> The way to get around this is to explicitly set the timezone in your R
> session (see ?timezone).  I can do this on my Ubuntu machine via:
> > Sys.setenv(TZ="GMT")
>
> Now if I run the code above again, there is no difference after
> converting from POSIXct -> numeric -> POSIXct:
> > (s <- Sys.time())
> [1] "2012-03-30 01:45:36 GMT"
> > as.POSIXct(as.numeric(s),origin="1970-01-01")
> [1] "2012-03-30 01:45:36 GMT"
>
> HTH,
>

Bingo!  Thaks heaps. I have been working on this and had got as far as
realising it was the conversion to numeric.  I was trying to set the time
zone in the as.POSIXct call but to no avail.  But this looks good.

cheers
W


> --
> Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>
> R/Finance 2012: Applied Finance with R
> www.RinFinance.com
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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 via email to