[R-SIG-Finance] Milliseconds to proper date/time class
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Feb 8 15:24:16 CET 2008
Try this:
library(zoo)
z <- zoo(1:10, 1001:1010)
Now <- Sys.time()
Epoch <- Now - as.numeric(Now)
zct <- aggregate(z, time(z) + Epoch, force)
# If you like you can convert it to chron
# from there; however, its possible that chron
# does not support as high a resolution
# so collapse equal valued times just in case
# Below we take the last one but you could take
# the mean or other value if you prefer or you could
# use force in place of tail, 1 and if that works then
# your times are far enough apart or your machine
# has enough resolution to represent them distinctly
# in chron.
library(chron)
zchron.gmt <- aggregate(zct, as.chron, tail, 1)
zhcron.local <- aggregate(zct, function(x) as.chron(x, tz = ""), tail, 1)
Suggest you read RNews 4/1 and see ?aggregate.zoo
Also read the three zoo vignettes.
On Feb 8, 2008 5:49 AM, <guiseppe.milicia at hsbcib.com> wrote:
> Guys,
>
> I'm importing high frequency time series data into R. I'm using the zoo
> timeseries class which works quite well.
>
> At the moment the times of my series are specified as milliseconds since
> epoch. The issue is that the X axis in plots is not all that useful, the
> same goes for things like window, etc.
>
> I was wondering what would be the reccomended way to convert from that
> representation to a proper date/time representation that works with zoo,
> e.g. Posixct?
>
> I would imagine this to be a rather common problem, but my searches have
> been unfruitful...
>
> Cheers,
>
> -- Giuseppe
>
> ************************************************************
> HSBC Bank plc may be solicited in the course of its placement efforts for a
> new issue, by investment clients of the firm for whom the Bank as a firm
> already provides other services. It may equally decide to allocate to its
> own proprietary book or with an associate of HSBC Group. This represents a
> potential conflict of interest. HSBC Bank plc has internal arrangements
> designed to ensure that the firm would give unbiased and full advice to the
> corporate finance client about the valuation and pricing of the offering as
> well as internal systems, controls and procedures to identify and manage
> conflicts of interest.
>
> HSBC Bank plc
> Registered Office: 8 Canada Square, London E14 5HQ, United Kingdom
> Registered in England - Number 14259
> Authorised and regulated by the Financial Services Authority.
> ************************************************************
>
>
> -----------------------------------------
> SAVE PAPER - THINK BEFORE YOU PRINT!
>
> This transmission has been issued by a member of the HSBC Group
> "HSBC" for the information of the addressee only and should not be
> reproduced and/or distributed to any other person. Each page
> attached hereto must be read in conjunction with any disclaimer
> which forms part of it. Unless otherwise stated, this transmission
> is neither an offer nor the solicitation of an offer to sell or
> purchase any investment. Its contents are based on information
> obtained from sources believed to be reliable but HSBC makes no
> representation and accepts no responsibility or liability as to its
> completeness or accuracy.
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>
More information about the R-SIG-Finance
mailing list